Files
moby/integration-cli/requirement/requirement.go
Sebastiaan van Stijn a4b0d32fa6 integration-cli: remove // import comments
These comments were added to enforce using the correct import path for
our packages ("github.com/docker/docker", not "github.com/moby/moby").
However, when working in go module mode (not GOPATH / vendor), they have
no effect, so their impact is limited.

Remove these imports in preparation of migrating our code to become an
actual go module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-30 15:59:13 +02:00

31 lines
722 B
Go

package requirement
import (
"path"
"reflect"
"runtime"
"strings"
"testing"
)
// 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(t *testing.T, requirements ...Test) {
t.Helper()
for _, r := range requirements {
isValid := r()
if !isValid {
requirementFunc := runtime.FuncForPC(reflect.ValueOf(r).Pointer()).Name()
t.Skipf("unmatched requirement %s", extractRequirement(requirementFunc))
}
}
}
func extractRequirement(requirementFunc string) string {
requirement := path.Base(requirementFunc)
return strings.SplitN(requirement, ".", 2)[1]
}