Skip to content

Commit 395bad1

Browse files
committed
chore: apply go fix modernizations (any, reflect.TypeFor, min, for range)
1 parent 8b2d942 commit 395bad1

8 files changed

Lines changed: 33 additions & 36 deletions

File tree

internal/core/options_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestWithIdentityProviderGroupsFilter(t *testing.T) {
1515

1616
got := WithIdentityProviderGroupsFilter(filter)
1717

18-
if reflect.TypeOf(got) != reflect.TypeOf(sso) {
18+
if reflect.TypeFor[SyncServiceOption]() != reflect.TypeFor[SyncServiceOption]() {
1919
t.Errorf("WithIdentityProviderGroupsFilter() return %T, different type than %T", got, sso)
2020
}
2121
})
@@ -64,7 +64,7 @@ func TestWithIdentityProviderUsersFilter(t *testing.T) {
6464

6565
got := WithIdentityProviderUsersFilter(filter)
6666

67-
if reflect.TypeOf(got) != reflect.TypeOf(sso) {
67+
if reflect.TypeFor[SyncServiceOption]() != reflect.TypeFor[SyncServiceOption]() {
6868
t.Errorf("WithIdentityProviderUsersFilter() return %T, different type than %T", got, sso)
6969
}
7070
})

internal/idp/helpers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func toEmails(e any) ([]model.Email, error) {
157157

158158
modelEmails := make([]model.Email, 0, len(emails))
159159
for _, email := range emails {
160-
emailMap, ok := email.(map[string]interface{})
160+
emailMap, ok := email.(map[string]any)
161161
if !ok {
162162
return nil, fmt.Errorf("error converting email: %v", email)
163163
}
@@ -197,7 +197,7 @@ func toLanguages(l any) (string, error) {
197197

198198
var preferredLanguage string
199199
for _, language := range languages {
200-
languageMap, ok := language.(map[string]interface{})
200+
languageMap, ok := language.(map[string]any)
201201
if !ok {
202202
// try to convert to *admin.UserLanguage
203203
if lang, ok := language.(*admin.UserLanguage); ok {
@@ -233,7 +233,7 @@ func toAddresses(a any) ([]model.Address, error) {
233233

234234
modelAddresses := make([]model.Address, 0, len(addresses))
235235
for _, address := range addresses {
236-
addressMap, ok := address.(map[string]interface{})
236+
addressMap, ok := address.(map[string]any)
237237
if !ok {
238238
// try to convert to *admin.UserAddress
239239
if addr, ok := address.(*admin.UserAddress); ok {
@@ -276,7 +276,7 @@ func toPhones(p any) ([]model.PhoneNumber, error) {
276276

277277
modelPhoneNumbers := make([]model.PhoneNumber, 0, len(phones))
278278
for _, phone := range phones {
279-
phoneMap, ok := phone.(map[string]interface{})
279+
phoneMap, ok := phone.(map[string]any)
280280
if !ok {
281281
// try to convert to *admin.UserPhone
282282
if ph, ok := phone.(*admin.UserPhone); ok {
@@ -321,7 +321,7 @@ func toRelations(r any) (*model.Manager, error) {
321321

322322
var manager *model.Manager
323323
for _, relation := range relations {
324-
relationMap, ok := relation.(map[string]interface{})
324+
relationMap, ok := relation.(map[string]any)
325325
if !ok {
326326
// try to convert to *admin.UserRelation
327327
if rel, ok := relation.(*admin.UserRelation); ok {
@@ -368,7 +368,7 @@ func toOrganizations(o any, manager *model.Manager) (*model.EnterpriseData, stri
368368
var mainOrganization *model.EnterpriseData
369369
var title string
370370
for _, organization := range organizations {
371-
organizationMap, ok := organization.(map[string]interface{})
371+
organizationMap, ok := organization.(map[string]any)
372372
if !ok {
373373
// try to convert to *admin.UserOrganization
374374
if org, ok := organization.(*admin.UserOrganization); ok {

internal/idp/helpers_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ func Test_buildUser(t *testing.T) {
7474
{
7575
name: "should return a valid user with all the fields and using primary email as the only email",
7676
given: &admin.User{
77-
Addresses: []interface{}{
78-
map[string]interface{}{"formatted": "formatted work", "type": "work"},
79-
map[string]interface{}{"formatted": "formatted home", "type": "home"},
77+
Addresses: []any{
78+
map[string]any{"formatted": "formatted work", "type": "work"},
79+
map[string]any{"formatted": "formatted home", "type": "home"},
8080
},
81-
Languages: []interface{}{map[string]interface{}{"languageCode": "languageCode", "preference": "preferred"}},
82-
Organizations: []interface{}{map[string]interface{}{"costCenter": "costCenter", "department": "department", "name": "name", "title": "title", "primary": true}},
83-
Phones: []interface{}{
84-
map[string]interface{}{"value": "value work", "type": "work"},
85-
map[string]interface{}{"value": "value home", "type": "home"},
81+
Languages: []any{map[string]any{"languageCode": "languageCode", "preference": "preferred"}},
82+
Organizations: []any{map[string]any{"costCenter": "costCenter", "department": "department", "name": "name", "title": "title", "primary": true}},
83+
Phones: []any{
84+
map[string]any{"value": "value work", "type": "work"},
85+
map[string]any{"value": "value home", "type": "home"},
8686
},
8787
Id: "id",
8888
Kind: "kind",
@@ -136,16 +136,16 @@ func Test_buildUser(t *testing.T) {
136136
{
137137
name: "should return a valid user with all the fields",
138138
given: &admin.User{
139-
Addresses: []interface{}{
140-
map[string]interface{}{"formatted": "formatted work", "type": "work"},
141-
map[string]interface{}{"formatted": "formatted home", "type": "home"},
139+
Addresses: []any{
140+
map[string]any{"formatted": "formatted work", "type": "work"},
141+
map[string]any{"formatted": "formatted home", "type": "home"},
142142
},
143-
Emails: []interface{}{map[string]interface{}{"address": "user@mail.com", "type": "work", "primary": true}},
144-
Languages: []interface{}{map[string]interface{}{"languageCode": "languageCode", "preference": "preferred"}},
145-
Organizations: []interface{}{map[string]interface{}{"costCenter": "costCenter", "department": "department", "name": "name", "title": "title", "primary": true}},
146-
Phones: []interface{}{
147-
map[string]interface{}{"value": "value work", "type": "work"},
148-
map[string]interface{}{"value": "value home", "type": "home"},
143+
Emails: []any{map[string]any{"address": "user@mail.com", "type": "work", "primary": true}},
144+
Languages: []any{map[string]any{"languageCode": "languageCode", "preference": "preferred"}},
145+
Organizations: []any{map[string]any{"costCenter": "costCenter", "department": "department", "name": "name", "title": "title", "primary": true}},
146+
Phones: []any{
147+
map[string]any{"value": "value work", "type": "work"},
148+
map[string]any{"value": "value home", "type": "home"},
149149
},
150150
Id: "id",
151151
Kind: "kind",

internal/scim/scim.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,7 @@ func (s *Provider) patchGroupOperations(op, path string, pvs []patchValue, gms *
469469
} else {
470470
if len(pvs) > s.maxMembersPerRequest {
471471
for i := 0; i < len(pvs); i += s.maxMembersPerRequest {
472-
end := i + s.maxMembersPerRequest
473-
if end > len(pvs) {
474-
end = len(pvs)
475-
}
472+
end := min(i+s.maxMembersPerRequest, len(pvs))
476473
chunks = append(chunks, pvs[i:end])
477474
}
478475
} else {

internal/scim/scim_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ func TestProvider_GetGroupsMembersBruteForce(t *testing.T) {
16211621
calls := 4
16221622
wg.Add(calls)
16231623

1624-
for i := 0; i < calls; i++ {
1624+
for range calls {
16251625
m.EXPECT().ListGroups(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, _ string) (*aws.ListGroupsResponse, error) {
16261626
mu.Lock()
16271627
currentConcurrent++

internal/setup/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func Secrets(cfg *config.Config) error {
194194
}()
195195

196196
// wait for all the goroutines to finish
197-
for i := 0; i < 4; i++ {
197+
for range 4 {
198198
if err := <-results; err != nil {
199199
return err
200200
}

pkg/aws/scim_model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ type Member struct {
295295
// Group represent a group entity
296296
type Group struct {
297297
ID string `json:"id"`
298-
Meta Meta `json:"meta,omitempty"`
298+
Meta Meta `json:"meta"`
299299
Schemas []string `json:"schemas,omitempty"`
300300
DisplayName string `json:"displayName"`
301301
ExternalID string `json:"externalId,omitempty"`

pkg/google/options_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func TestWithIncludeDerivedMembership(t *testing.T) {
1111

1212
got := WithIncludeDerivedMembership(false)
1313

14-
if reflect.TypeOf(got) != reflect.TypeOf(ggmo) {
14+
if reflect.TypeFor[GetGroupMembersOption]() != reflect.TypeFor[GetGroupMembersOption]() {
1515
t.Errorf("WithIncludeDerivedMembership() return %T, different type than %T", got, ggmo)
1616
}
1717
})
@@ -36,7 +36,7 @@ func TestWithMaxResults(t *testing.T) {
3636
var ggmo GetGroupMembersOption
3737
got := WithMaxResults(100)
3838

39-
if reflect.TypeOf(got) != reflect.TypeOf(ggmo) {
39+
if reflect.TypeFor[GetGroupMembersOption]() != reflect.TypeFor[GetGroupMembersOption]() {
4040
t.Errorf("WithMaxResults() return %T, different type than %T", got, ggmo)
4141
}
4242
})
@@ -61,7 +61,7 @@ func TestWithPageToken(t *testing.T) {
6161
var ggmo GetGroupMembersOption
6262
got := WithPageToken("thisIsAToken")
6363

64-
if reflect.TypeOf(got) != reflect.TypeOf(ggmo) {
64+
if reflect.TypeFor[GetGroupMembersOption]() != reflect.TypeFor[GetGroupMembersOption]() {
6565
t.Errorf("WithPageToken() return %T, different type than %T", got, ggmo)
6666
}
6767
})
@@ -86,7 +86,7 @@ func TestWithRoles(t *testing.T) {
8686
var ggmo GetGroupMembersOption
8787
got := WithRoles("OWNER,MANAGER,MEMBER")
8888

89-
if reflect.TypeOf(got) != reflect.TypeOf(ggmo) {
89+
if reflect.TypeFor[GetGroupMembersOption]() != reflect.TypeFor[GetGroupMembersOption]() {
9090
t.Errorf("WithRoles() return %T, different type than %T", got, ggmo)
9191
}
9292
})

0 commit comments

Comments
 (0)