package skipper import ( "testing" "github.com/stretchr/testify/assert" ) func TestLabelSkipping(t *testing.T) { tcs := map[string]struct { labels map[string]string skip map[string]string input map[string]string expected bool }{ "labels": { map[string]string{"bear": "apple"}, nil, map[string]string{"bear": "apple", "a": "b"}, false, }, "labels-skip-simple": { map[string]string{"a": "b", "martial-arts": "karate"}, nil, map[string]string{"bear": "apple"}, true, }, "labels-skip-multiple": { map[string]string{"a": "b", "martial-arts": "karate"}, nil, map[string]string{"bear": "apple", "body": "builder"}, true, }, "labels-skip-multiple-partial": { map[string]string{"a": "b", "martial-arts": "karate", "bear": "apple"}, nil, map[string]string{"bear": "apple", "body": "builder"}, true, }, "labels-multiple": { map[string]string{"a": "b", "bear": "apple", "martial-arts": "karate"}, nil, map[string]string{"bear": "apple", "a": "b", "key": "benz", "dreaming": "gently", "martial-arts": "karate"}, false, }, "skip-labels-one-match": { nil, map[string]string{"a": "b", "bear": "apple", "martial-arts": "karate"}, map[string]string{"bear": "apple", "key": "benz", "dreaming": "gently"}, true, }, "skip-labels-multiple-match": { nil, map[string]string{"a": "b", "bear": "apple", "martial-arts": "karate"}, map[string]string{"bear": "apple", "a": "b", "key": "benz", "dreaming": "gently"}, true, }, "skip-if-no-labels-when": { map[string]string{"a": "b", "bear": "apple", "martial-arts": "karate"}, nil, map[string]string{}, true, }, } for name, tc := range tcs { t.Run(name, func(t *testing.T) { skip, _ := SkipBasedOnLabels(tc.input, tc.labels, tc.skip) assert.Equal(t, tc.expected, skip) }) } }