package skipper import "fmt" // SkipBasedOnLabels determines if a test should be skipped based on label maps // which should be executed and labels that should be skipped. // This function is defined independently of the framework package // so that it may be used by Ginkgo & Golang tests. func SkipBasedOnLabels(test, labels, skip map[string]string) (bool, string) { // handle test block with no labels, dont run it if -labels is provided if len(test) == 0 && len(labels) != 0 { return true, "test without labels skipped due to -labels flag being provided" } // evalute skip labels first bc we should exit sooner on average if skip != nil && len(test) != 0 { for k := range test { if v, ok := skip[k]; ok && v == test[k] { return true, fmt.Sprintf("test with label %s=%s skipped due to -skip-labels flag", k, labels[k]) } } } if len(labels) != 0 { matches := map[string]bool{} // match all labels for k := range labels { matches[k] = false if v, ok := test[k]; ok && v == labels[k] { matches[k] = true } } skip := false for _, match := range matches { if !match { skip = true } } if skip { return true, fmt.Sprintf("test without labels skipped due to -labels flag: %v", labels) } } return false, "" }