diff --git a/kubernetes-rbac-synchroniser.go b/kubernetes-rbac-synchroniser.go index a66485a..d9ae83b 100644 --- a/kubernetes-rbac-synchroniser.go +++ b/kubernetes-rbac-synchroniser.go @@ -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. diff --git a/kubernetes-rbac-synchroniser_test.go b/kubernetes-rbac-synchroniser_test.go index e35bffc..218e1af 100644 --- a/kubernetes-rbac-synchroniser_test.go +++ b/kubernetes-rbac-synchroniser_test.go @@ -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) + } }