github.com/lacework-dev/go-moby@v20.10.12+incompatible/integration-cli/requirement/requirement.go (about)

     1  package requirement // import "github.com/docker/docker/integration-cli/requirement"
     2  
     3  import (
     4  	"path"
     5  	"reflect"
     6  	"runtime"
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  // Test represent a function that can be used as a requirement validation.
    12  type Test func() bool
    13  
    14  // Is checks if the environment satisfies the requirements
    15  // for the test to run or skips the tests.
    16  func Is(t *testing.T, requirements ...Test) {
    17  	t.Helper()
    18  	for _, r := range requirements {
    19  		isValid := r()
    20  		if !isValid {
    21  			requirementFunc := runtime.FuncForPC(reflect.ValueOf(r).Pointer()).Name()
    22  			t.Skipf("unmatched requirement %s", extractRequirement(requirementFunc))
    23  		}
    24  	}
    25  }
    26  
    27  func extractRequirement(requirementFunc string) string {
    28  	requirement := path.Base(requirementFunc)
    29  	return strings.SplitN(requirement, ".", 2)[1]
    30  }