refactor(watcher): make authSliceToMap always return map
This commit is contained in:
@@ -263,9 +263,6 @@ func (w *Watcher) computePerPathUpdatesLocked(oldByID, newByID map[string]*corea
|
|||||||
}
|
}
|
||||||
|
|
||||||
func authSliceToMap(auths []*coreauth.Auth) map[string]*coreauth.Auth {
|
func authSliceToMap(auths []*coreauth.Auth) map[string]*coreauth.Auth {
|
||||||
if len(auths) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
byID := make(map[string]*coreauth.Auth, len(auths))
|
byID := make(map[string]*coreauth.Auth, len(auths))
|
||||||
for _, a := range auths {
|
for _, a := range auths {
|
||||||
if a == nil || strings.TrimSpace(a.ID) == "" {
|
if a == nil || strings.TrimSpace(a.ID) == "" {
|
||||||
@@ -273,9 +270,6 @@ func authSliceToMap(auths []*coreauth.Auth) map[string]*coreauth.Auth {
|
|||||||
}
|
}
|
||||||
byID[a.ID] = a
|
byID[a.ID] = a
|
||||||
}
|
}
|
||||||
if len(byID) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return byID
|
return byID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -489,17 +489,17 @@ func TestAuthSliceToMap(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "nil input",
|
name: "nil input",
|
||||||
in: nil,
|
in: nil,
|
||||||
want: nil,
|
want: map[string]*coreauth.Auth{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty input",
|
name: "empty input",
|
||||||
in: []*coreauth.Auth{},
|
in: []*coreauth.Auth{},
|
||||||
want: nil,
|
want: map[string]*coreauth.Auth{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "filters invalid auths",
|
name: "filters invalid auths",
|
||||||
in: []*coreauth.Auth{nil, empty},
|
in: []*coreauth.Auth{nil, empty},
|
||||||
want: nil,
|
want: map[string]*coreauth.Auth{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "keeps valid auths",
|
name: "keeps valid auths",
|
||||||
@@ -519,8 +519,11 @@ func TestAuthSliceToMap(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
got := authSliceToMap(tc.in)
|
got := authSliceToMap(tc.in)
|
||||||
if len(tc.want) == 0 {
|
if len(tc.want) == 0 {
|
||||||
if got != nil {
|
if got == nil {
|
||||||
t.Fatalf("expected nil map, got %#v", got)
|
t.Fatal("expected empty map, got nil")
|
||||||
|
}
|
||||||
|
if len(got) != 0 {
|
||||||
|
t.Fatalf("expected empty map, got %#v", got)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user