...

Source file src/edge-infra.dev/test/framework/skipper/skipper.go

Documentation: edge-infra.dev/test/framework/skipper

     1  package skipper
     2  
     3  import "fmt"
     4  
     5  // SkipBasedOnLabels determines if a test should be skipped based on label maps
     6  // which should be executed and labels that should be skipped.
     7  // This function is defined independently of the framework package
     8  // so that it may be used by Ginkgo & Golang tests.
     9  func SkipBasedOnLabels(test, labels, skip map[string]string) (bool, string) {
    10  	// handle test block with no labels, dont run it if -labels is provided
    11  	if len(test) == 0 && len(labels) != 0 {
    12  		return true, "test without labels skipped due to -labels flag being provided"
    13  	}
    14  
    15  	// evalute skip labels first bc we should exit sooner on average
    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  		// match all labels
    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