2018-02-05 21:05:59 +00:00
|
|
|
package requirement // import "github.com/docker/docker/integration-cli/requirement"
|
2016-12-16 14:13:23 +00:00
|
|
|
|
|
|
|
import (
|
2016-12-26 18:20:27 +00:00
|
|
|
"path"
|
2016-12-16 14:13:23 +00:00
|
|
|
"reflect"
|
|
|
|
"runtime"
|
2016-12-26 18:20:27 +00:00
|
|
|
"strings"
|
2019-10-09 19:06:15 +00:00
|
|
|
"testing"
|
2016-12-16 14:13:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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.
|
2019-10-09 19:06:15 +00:00
|
|
|
func Is(t *testing.T, requirements ...Test) {
|
|
|
|
t.Helper()
|
2016-12-16 14:13:23 +00:00
|
|
|
for _, r := range requirements {
|
|
|
|
isValid := r()
|
|
|
|
if !isValid {
|
|
|
|
requirementFunc := runtime.FuncForPC(reflect.ValueOf(r).Pointer()).Name()
|
2019-10-09 19:06:15 +00:00
|
|
|
t.Skipf("unmatched requirement %s", extractRequirement(requirementFunc))
|
2016-12-16 14:13:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-26 18:20:27 +00:00
|
|
|
|
|
|
|
func extractRequirement(requirementFunc string) string {
|
|
|
|
requirement := path.Base(requirementFunc)
|
|
|
|
return strings.SplitN(requirement, ".", 2)[1]
|
|
|
|
}
|