integration-cli: make testRequires() a Helper
Make this utility a helper, so that the "skip" message is printing the location of the test, instead of the location of the helper, which is what it's printing now: requirement.go:26: unmatched requirement bridgeNfIptables Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
dba8da8158
commit
6afe0f38f6
2 changed files with 8 additions and 10 deletions
|
@ -1,29 +1,25 @@
|
||||||
package requirement // import "github.com/docker/docker/integration-cli/requirement"
|
package requirement // import "github.com/docker/docker/integration-cli/requirement"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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.
|
// Test represent a function that can be used as a requirement validation.
|
||||||
type Test func() bool
|
type Test func() bool
|
||||||
|
|
||||||
// Is checks if the environment satisfies the requirements
|
// Is checks if the environment satisfies the requirements
|
||||||
// for the test to run or skips the tests.
|
// for the test to run or skips the tests.
|
||||||
func Is(s SkipT, requirements ...Test) {
|
func Is(t *testing.T, requirements ...Test) {
|
||||||
|
t.Helper()
|
||||||
for _, r := range requirements {
|
for _, r := range requirements {
|
||||||
isValid := r()
|
isValid := r()
|
||||||
if !isValid {
|
if !isValid {
|
||||||
requirementFunc := runtime.FuncForPC(reflect.ValueOf(r).Pointer()).Name()
|
requirementFunc := runtime.FuncForPC(reflect.ValueOf(r).Pointer()).Name()
|
||||||
s.Skip(fmt.Sprintf("unmatched requirement %s", extractRequirement(requirementFunc)))
|
t.Skipf("unmatched requirement %s", extractRequirement(requirementFunc))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
@ -190,6 +191,7 @@ func TODOBuildkit() bool {
|
||||||
|
|
||||||
// testRequires checks if the environment satisfies the requirements
|
// testRequires checks if the environment satisfies the requirements
|
||||||
// for the test to run or skips the tests.
|
// for the test to run or skips the tests.
|
||||||
func testRequires(c interface{}, requirements ...requirement.Test) {
|
func testRequires(t *testing.T, requirements ...requirement.Test) {
|
||||||
requirement.Is(c.(requirement.SkipT), requirements...)
|
t.Helper()
|
||||||
|
requirement.Is(t, requirements...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue