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>
| ... | ... |
@@ -1,29 +1,25 @@ |
| 1 | 1 |
package requirement // import "github.com/docker/docker/integration-cli/requirement" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "fmt" |
|
| 5 | 4 |
"path" |
| 6 | 5 |
"reflect" |
| 7 | 6 |
"runtime" |
| 8 | 7 |
"strings" |
| 8 |
+ "testing" |
|
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 |
-// SkipT is the interface required to skip tests |
|
| 12 |
-type SkipT interface {
|
|
| 13 |
- Skip(...interface{})
|
|
| 14 |
-} |
|
| 15 |
- |
|
| 16 | 11 |
// Test represent a function that can be used as a requirement validation. |
| 17 | 12 |
type Test func() bool |
| 18 | 13 |
|
| 19 | 14 |
// Is checks if the environment satisfies the requirements |
| 20 | 15 |
// for the test to run or skips the tests. |
| 21 |
-func Is(s SkipT, requirements ...Test) {
|
|
| 16 |
+func Is(t *testing.T, requirements ...Test) {
|
|
| 17 |
+ t.Helper() |
|
| 22 | 18 |
for _, r := range requirements {
|
| 23 | 19 |
isValid := r() |
| 24 | 20 |
if !isValid {
|
| 25 | 21 |
requirementFunc := runtime.FuncForPC(reflect.ValueOf(r).Pointer()).Name() |
| 26 |
- s.Skip(fmt.Sprintf("unmatched requirement %s", extractRequirement(requirementFunc)))
|
|
| 22 |
+ t.Skipf("unmatched requirement %s", extractRequirement(requirementFunc))
|
|
| 27 | 23 |
} |
| 28 | 24 |
} |
| 29 | 25 |
} |
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"os/exec" |
| 10 | 10 |
"strconv" |
| 11 | 11 |
"strings" |
| 12 |
+ "testing" |
|
| 12 | 13 |
"time" |
| 13 | 14 |
|
| 14 | 15 |
"github.com/docker/docker/api/types" |
| ... | ... |
@@ -190,6 +191,7 @@ func TODOBuildkit() bool {
|
| 190 | 190 |
|
| 191 | 191 |
// testRequires checks if the environment satisfies the requirements |
| 192 | 192 |
// for the test to run or skips the tests. |
| 193 |
-func testRequires(c interface{}, requirements ...requirement.Test) {
|
|
| 194 |
- requirement.Is(c.(requirement.SkipT), requirements...) |
|
| 193 |
+func testRequires(t *testing.T, requirements ...requirement.Test) {
|
|
| 194 |
+ t.Helper() |
|
| 195 |
+ requirement.Is(t, requirements...) |
|
| 195 | 196 |
} |