connectors: refactor filter code into a helper package

I hope I didn't miss any :D

Signed-off-by: Stephan Renatus <srenatus@chef.io>
This commit is contained in:
Stephan Renatus
2019-07-03 10:40:31 +02:00
parent 39dc5dcfb7
commit 51f50fcad8
6 changed files with 55 additions and 66 deletions

26
pkg/groups/groups_test.go Normal file
View File

@@ -0,0 +1,26 @@
package groups_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/dexidp/dex/pkg/groups"
)
func TestFilter(t *testing.T) {
cases := map[string]struct {
given, required, expected []string
}{
"nothing given": {given: []string{}, required: []string{"ops"}, expected: []string{}},
"exactly one match": {given: []string{"foo"}, required: []string{"foo"}, expected: []string{"foo"}},
"no group of the required ones": {given: []string{"foo", "bar"}, required: []string{"baz"}, expected: []string{}},
"subset matching": {given: []string{"foo", "bar", "baz"}, required: []string{"bar", "baz"}, expected: []string{"bar", "baz"}},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
actual := groups.Filter(tc.given, tc.required)
assert.ElementsMatch(t, tc.expected, actual)
})
}
}