...
1 package skipper
2
3 import "fmt"
4
5
6
7
8
9 func SkipBasedOnLabels(test, labels, skip map[string]string) (bool, string) {
10
11 if len(test) == 0 && len(labels) != 0 {
12 return true, "test without labels skipped due to -labels flag being provided"
13 }
14
15
16 if skip != nil && len(test) != 0 {
17 for k := range test {
18 if v, ok := skip[k]; ok && v == test[k] {
19 return true, fmt.Sprintf("test with label %s=%s skipped due to -skip-labels flag", k, labels[k])
20 }
21 }
22 }
23
24 if len(labels) != 0 {
25 matches := map[string]bool{}
26
27 for k := range labels {
28 matches[k] = false
29 if v, ok := test[k]; ok && v == labels[k] {
30 matches[k] = true
31 }
32 }
33 skip := false
34 for _, match := range matches {
35 if !match {
36 skip = true
37 }
38 }
39 if skip {
40 return true, fmt.Sprintf("test without labels skipped due to -labels flag: %v", labels)
41 }
42 }
43
44 return false, ""
45 }
46
View as plain text