Skip to content

Commit

Permalink
Fix linter errors in files
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-gregory-ovo committed Dec 13, 2023
1 parent 4b4d5c7 commit 0ecc1ee
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 234 deletions.
12 changes: 9 additions & 3 deletions adapters/azuread/groupmembership/groupmembership.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@ type iClient interface {
var _ iClient = &msgraphsdkgo.GraphServiceClient{}

type iGroupClient interface {
Get(context.Context, *groups.GroupsRequestBuilderGetRequestConfiguration) (models.GroupCollectionResponseable, error)
ByGroupId(string) *groups.GroupItemRequestBuilder
Get(
ctx context.Context,
config *groups.GroupsRequestBuilderGetRequestConfiguration,
) (models.GroupCollectionResponseable, error)
ByGroupId(id string) *groups.GroupItemRequestBuilder
}

var _ iGroupClient = &groups.GroupsRequestBuilder{}

type iUserClient interface {
Get(context.Context, *users.UsersRequestBuilderGetRequestConfiguration) (models.UserCollectionResponseable, error)
Get(
ctx context.Context,
config *users.UsersRequestBuilderGetRequestConfiguration,
) (models.UserCollectionResponseable, error)
}

var _ iUserClient = &users.UsersRequestBuilder{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ func TestIntegration(t *testing.T) {
adapter, err := Init(ctx, map[gosync.ConfigKey]string{
GroupName: *group,
})
assert.NoError(t, err)
require.NoError(t, err)

emails, err := adapter.Get(ctx)
assert.NoError(t, err)
require.NoError(t, err)
assert.NotContainsf(t, emails, *email, "Email %s already exists in the group %s", *email, *group)

err = adapter.Add(ctx, []string{*email})
assert.NoError(t, err)
require.NoError(t, err)

emails, err = adapter.Get(ctx)
assert.NoError(t, err)
require.NoError(t, err)
assert.Containsf(t, emails, *email, "Email %s not found after adding it to the group", *email)

err = adapter.Remove(ctx, []string{*email})
assert.NoError(t, err)
require.NoError(t, err)

emails, err = adapter.Get(ctx)
assert.NoError(t, err)
require.NoError(t, err)
assert.NotContainsf(t, emails, *email, "Email %s still exists after removing it from the group %s", *email, *group)
}
29 changes: 14 additions & 15 deletions adapters/azuread/groupmembership/groupmembership_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/microsoftgraph/msgraph-sdk-go/users"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

gosync "github.com/ovotech/go-sync"
)
Expand All @@ -32,7 +33,7 @@ func TestInit(t *testing.T) {
GroupName: "example",
})

assert.NoError(t, err)
require.NoError(t, err)
assert.IsType(t, &GroupMembership{}, adapter)
assert.Equal(t, "example", adapter.group)
})
Expand All @@ -45,7 +46,7 @@ func TestInit(t *testing.T) {

_, err := Init(ctx, map[gosync.ConfigKey]string{})

assert.ErrorIs(t, err, gosync.ErrMissingConfig)
require.ErrorIs(t, err, gosync.ErrMissingConfig)
})
})
}
Expand Down Expand Up @@ -87,7 +88,7 @@ func Test_resolveGroupID(t *testing.T) {

gid, err := resolveGroupID(ctx, client, group)
assert.Empty(t, gid)
assert.ErrorIs(t, err, ErrNoResults)
require.ErrorIs(t, err, ErrNoResults)
})

t.Run("one found", func(t *testing.T) {
Expand All @@ -97,7 +98,7 @@ func Test_resolveGroupID(t *testing.T) {

gid, err := resolveGroupID(ctx, client, group)
assert.Contains(t, gid, "00000001-0000-0000-0000-000123456789")
assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("multiple found", func(t *testing.T) {
Expand All @@ -110,7 +111,7 @@ func Test_resolveGroupID(t *testing.T) {

gid, err := resolveGroupID(ctx, client, group)
assert.Empty(t, gid)
assert.ErrorIs(t, err, ErrTooManyResults)
require.ErrorIs(t, err, ErrTooManyResults)
})
}

Expand Down Expand Up @@ -151,7 +152,7 @@ func Test_resolveUserID(t *testing.T) {

gid, err := resolveUserID(ctx, client, email)
assert.Empty(t, gid)
assert.ErrorIs(t, err, ErrNoResults)
require.ErrorIs(t, err, ErrNoResults)
})

t.Run("one found", func(t *testing.T) {
Expand All @@ -161,7 +162,7 @@ func Test_resolveUserID(t *testing.T) {

gid, err := resolveUserID(ctx, client, email)
assert.Contains(t, gid, "00000001-1000-0000-0000-000123456789")
assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("multiple found", func(t *testing.T) {
Expand All @@ -171,7 +172,7 @@ func Test_resolveUserID(t *testing.T) {

gid, err := resolveUserID(ctx, client, email)
assert.Empty(t, gid)
assert.ErrorIs(t, err, ErrTooManyResults)
require.ErrorIs(t, err, ErrTooManyResults)
})
}

Expand Down Expand Up @@ -229,11 +230,10 @@ func TestGroupMembership_Get(t *testing.T) {
}

out, err := adapter.Get(ctx)
assert.NoError(t, err)
require.NoError(t, err)
assert.ElementsMatch(t, out, expected)
}

//nolint:funlen
func TestGroupMembership_Add(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -312,10 +312,9 @@ func TestGroupMembership_Add(t *testing.T) {

expected := []string{userMail1, userMail2}
err := adapter.Add(ctx, expected)
assert.NoError(t, err)
require.NoError(t, err)
}

//nolint:funlen
func TestGroupMembership_Remove(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -384,7 +383,7 @@ func TestGroupMembership_Remove(t *testing.T) {
}

err := adapter.Remove(ctx, []string{userMail1, userMail2})
assert.NoError(t, err)
require.NoError(t, err)
}

type MockRequestAdapter struct {
Expand Down Expand Up @@ -467,11 +466,11 @@ func (r *MockRequestAdapter) GetSerializationWriterFactory() serialization.Seria
func (r *MockRequestAdapter) EnableBackingStore(_ store.BackingStoreFactory) {
}

//nolint:revive,stylecheck
//nolint:stylecheck
func (r *MockRequestAdapter) SetBaseUrl(_ string) {
}

//nolint:revive,stylecheck
//nolint:stylecheck
func (r *MockRequestAdapter) GetBaseUrl() string {
return ""
}
5 changes: 4 additions & 1 deletion adapters/azuread/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ See the [reference] for more information on filter queries.
const Filter gosync.ConfigKey = "filter"

type iUser interface {
Get(context.Context, *users.UsersRequestBuilderGetRequestConfiguration) (models.UserCollectionResponseable, error)
Get(
ctx context.Context,
config *users.UsersRequestBuilderGetRequestConfiguration,
) (models.UserCollectionResponseable, error)
}

type iClient interface {
Expand Down
4 changes: 2 additions & 2 deletions adapters/azuread/user/user_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func TestIntegration(t *testing.T) {
adapter, err := Init(ctx, map[gosync.ConfigKey]string{
Filter: fmt.Sprintf("mail eq '%s'", *email),
})
assert.NoError(t, err)
require.NoError(t, err)

emails, err := adapter.Get(ctx)
assert.NoError(t, err)
require.NoError(t, err)
assert.ElementsMatch(t, emails, []string{*email})
}
19 changes: 10 additions & 9 deletions adapters/azuread/user/user_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

gosync "github.com/ovotech/go-sync"
)
Expand Down Expand Up @@ -95,11 +96,11 @@ func (r *MockRequestAdapter) GetSerializationWriterFactory() serialization.Seria
func (r *MockRequestAdapter) EnableBackingStore(_ store.BackingStoreFactory) {
}

//nolint:revive,stylecheck
//nolint:stylecheck
func (r *MockRequestAdapter) SetBaseUrl(_ string) {
}

//nolint:revive,stylecheck
//nolint:stylecheck
func (r *MockRequestAdapter) GetBaseUrl() string {
return ""
}
Expand All @@ -115,7 +116,7 @@ func TestTeam_Get(t *testing.T) {
mockClient.EXPECT().GetAdapter().Return(&MockRequestAdapter{})

adapter, err := Init(context.TODO(), nil, WithClient(mockClient))
assert.NoError(t, err)
require.NoError(t, err)

adapter.users = mockUser

Expand Down Expand Up @@ -149,11 +150,11 @@ func TestTeam_Add(t *testing.T) {
mockClient := newMockIClient(t)

adapter, err := Init(context.TODO(), nil, WithClient(mockClient))
assert.NoError(t, err)
require.NoError(t, err)

err = adapter.Add(context.TODO(), []string{"foo@email", "bar@email"})

assert.ErrorIs(t, err, gosync.ErrReadOnly)
require.ErrorIs(t, err, gosync.ErrReadOnly)
}

func TestTeam_Remove(t *testing.T) {
Expand All @@ -162,11 +163,11 @@ func TestTeam_Remove(t *testing.T) {
mockClient := newMockIClient(t)

adapter, err := Init(context.TODO(), nil, WithClient(mockClient))
assert.NoError(t, err)
require.NoError(t, err)

err = adapter.Remove(context.TODO(), []string{"foo@email", "bar@email"})

assert.ErrorIs(t, err, gosync.ErrReadOnly)
require.ErrorIs(t, err, gosync.ErrReadOnly)
}

func Test_isAdvancedQuery(t *testing.T) {
Expand Down Expand Up @@ -220,7 +221,7 @@ func TestInit(t *testing.T) {
Filter: "filter",
})

assert.NoError(t, err)
require.NoError(t, err)
assert.IsType(t, &User{}, adapter)
assert.Equal(t, "filter", adapter.filter)
})
Expand All @@ -233,7 +234,7 @@ func TestInit(t *testing.T) {

adapter, err := Init(ctx, map[gosync.ConfigKey]string{})

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, "", adapter.filter)
})
})
Expand Down
4 changes: 2 additions & 2 deletions adapters/github/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import "context"
// GitHubDiscovery is required because there are multiple ways to convert a GitHub email into a username.
// At OVO we use SAML, but other organisations may use public emails or another mechanism.
type GitHubDiscovery interface {
GetUsernameFromEmail(context.Context, []string) ([]string, error)
GetEmailFromUsername(context.Context, []string) ([]string, error)
GetUsernameFromEmail(ctx context.Context, emails []string) ([]string, error)
GetEmailFromUsername(ctx context.Context, usernames []string) ([]string, error)
}
16 changes: 8 additions & 8 deletions adapters/github/discovery/saml/saml_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/shurcooL/githubv4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

func emailQueryFunc(names ...string) func(ctx context.Context, q interface{}, variables map[string]interface{}) {
Expand Down Expand Up @@ -50,7 +51,6 @@ func TestNew(t *testing.T) {
assert.Zero(t, gitHubClient.Calls)
}

//nolint:funlen
func TestSaml_GetUsernameFromEmail(t *testing.T) {
t.Parallel()

Expand All @@ -76,7 +76,7 @@ func TestSaml_GetUsernameFromEmail(t *testing.T) {

usernames, err := discovery.GetUsernameFromEmail(ctx, []string{"foo@email", "bar@email"})

assert.NoError(t, err)
require.NoError(t, err)
assert.ElementsMatch(t, usernames, []string{"foo", "bar"})
})

Expand All @@ -100,7 +100,7 @@ func TestSaml_GetUsernameFromEmail(t *testing.T) {

_, err := discovery.GetUsernameFromEmail(ctx, []string{"foo@email", "bar@email"})

assert.ErrorIs(t, err, ErrUserNotFound)
require.ErrorIs(t, err, ErrUserNotFound)
})

t.Run("MuteUserNotFoundErr true returns all non-failing results", func(t *testing.T) { //nolint: dupl
Expand All @@ -123,12 +123,12 @@ func TestSaml_GetUsernameFromEmail(t *testing.T) {

usernames, err := discovery.GetUsernameFromEmail(ctx, []string{"foo@email", "bar@email"})

assert.NoError(t, err)
require.NoError(t, err)
assert.ElementsMatch(t, usernames, []string{"foo"})
})
}

func TestSaml_GetEmailFromUsername(t *testing.T) { //nolint: funlen
func TestSaml_GetEmailFromUsername(t *testing.T) {
t.Parallel()

ctx := context.TODO()
Expand All @@ -152,7 +152,7 @@ func TestSaml_GetEmailFromUsername(t *testing.T) { //nolint: funlen

usernames, err := discovery.GetEmailFromUsername(ctx, []string{"foo", "bar"})

assert.NoError(t, err)
require.NoError(t, err)
assert.ElementsMatch(t, usernames, []string{"foo@email", "bar@email"})
})

Expand All @@ -176,7 +176,7 @@ func TestSaml_GetEmailFromUsername(t *testing.T) { //nolint: funlen

_, err := discovery.GetEmailFromUsername(ctx, []string{"foo", "bar"})

assert.ErrorIs(t, err, ErrUserNotFound)
require.ErrorIs(t, err, ErrUserNotFound)
})

t.Run("MuteUserNotFoundErr true returns all non-failing results", func(t *testing.T) { //nolint: dupl
Expand All @@ -199,7 +199,7 @@ func TestSaml_GetEmailFromUsername(t *testing.T) { //nolint: funlen

usernames, err := discovery.GetEmailFromUsername(ctx, []string{"foo", "bar"})

assert.NoError(t, err)
require.NoError(t, err)
assert.ElementsMatch(t, usernames, []string{"foo@email"})
})
}
Loading

0 comments on commit 0ecc1ee

Please sign in to comment.