1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration-cli/requirement/requirement.go
Tibor Vass 931edfe5e9 prepare for rm-gocheck script
Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-09 20:49:53 +00:00

34 lines
875 B
Go

package requirement // import "github.com/docker/docker/integration-cli/requirement"
import (
"fmt"
"path"
"reflect"
"runtime"
"strings"
)
// SkipT is the interface required to skip tests
type SkipT interface {
Skip(...interface{})
}
// Test represent a function that can be used as a requirement validation.
type Test func() bool
// Is checks if the environment satisfies the requirements
// for the test to run or skips the tests.
func Is(s SkipT, requirements ...Test) {
for _, r := range requirements {
isValid := r()
if !isValid {
requirementFunc := runtime.FuncForPC(reflect.ValueOf(r).Pointer()).Name()
s.Skip(fmt.Sprintf("unmatched requirement %s", extractRequirement(requirementFunc)))
}
}
}
func extractRequirement(requirementFunc string) string {
requirement := path.Base(requirementFunc)
return strings.SplitN(requirement, ".", 2)[1]
}