Skip to content

Commit

Permalink
fix deduplicate func
Browse files Browse the repository at this point in the history
  • Loading branch information
yacut committed Nov 23, 2017
1 parent 884e8dc commit 98c351d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
19 changes: 11 additions & 8 deletions kubernetes-rbac-synchroniser.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,18 @@ func getMembers(service *admin.Service, email string) ([]*admin.Member, error) {
// Returns:
// Admin SDK member list.
func uniq(list []*admin.Member) []*admin.Member {
uniqueSet := make(map[*admin.Member]bool, len(list))
for _, x := range list {
uniqueSet[x] = true
}
result := make([]*admin.Member, 0, len(uniqueSet))
for x := range uniqueSet {
result = append(result, x)
var uniqSet []*admin.Member
loop:
for _, l := range list {
for _, x := range uniqSet {
if l.Email == x.Email {
continue loop
}
}
uniqSet = append(uniqSet, l)
}
return result

return uniqSet
}

// Build and returns a fake Admin members object.
Expand Down
9 changes: 9 additions & 0 deletions kubernetes-rbac-synchroniser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@ func TestUniq(t *testing.T) {
if list2Length != 3 {
t.Errorf("Uniq was incorrect, got: %d, want: %d.", list2Length, 3)
}
if uniqUserList2[0].Email != member1.Email {
t.Errorf("Uniq sort was incorrect, got: %q, want: %q.", uniqUserList2[0].Email, member1.Email)
}
if uniqUserList2[1].Email != member2.Email {
t.Errorf("Uniq sort was incorrect, got: %q, want: %q.", uniqUserList2[1].Email, member2.Email)
}
if uniqUserList2[2].Email != member3.Email {
t.Errorf("Uniq sort was incorrect, got: %q, want: %q.", uniqUserList2[2].Email, member3.Email)
}
}

0 comments on commit 98c351d

Please sign in to comment.