github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/integration-cli/requirement/requirement.go (about) 1 package requirement 2 3 import ( 4 "fmt" 5 "path" 6 "reflect" 7 "runtime" 8 "strings" 9 ) 10 11 // SkipT is the interface required to skip tests 12 type SkipT interface { 13 Skip(reason string) 14 } 15 16 // Test represent a function that can be used as a requirement validation. 17 type Test func() bool 18 19 // Is checks if the environment satisfies the requirements 20 // for the test to run or skips the tests. 21 func Is(s SkipT, requirements ...Test) { 22 for _, r := range requirements { 23 isValid := r() 24 if !isValid { 25 requirementFunc := runtime.FuncForPC(reflect.ValueOf(r).Pointer()).Name() 26 s.Skip(fmt.Sprintf("unmatched requirement %s", extractRequirement(requirementFunc))) 27 } 28 } 29 } 30 31 func extractRequirement(requirementFunc string) string { 32 requirement := path.Base(requirementFunc) 33 return strings.SplitN(requirement, ".", 2)[1] 34 }