Skip to content

Commit ca9bec9

Browse files
committed
test: add HasFeatureCompat helper
This is intended to act as a helper to allow checking for the presence of sandbox worker features without skipping a test (which allows for defining different behavior if a feature is available or not). Signed-off-by: Justin Chadwell <[email protected]>
1 parent b49a887 commit ca9bec9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

util/testutil/integration/sandbox.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/google/shlex"
1515
"github.com/moby/buildkit/util/bklog"
16+
"github.com/pkg/errors"
1617
)
1718

1819
const buildkitdConfigFile = "buildkitd.toml"
@@ -156,6 +157,13 @@ func FormatLogs(m map[string]*bytes.Buffer) string {
156157
}
157158

158159
func CheckFeatureCompat(t *testing.T, sb Sandbox, features map[string]struct{}, reason ...string) {
160+
t.Helper()
161+
if err := HasFeatureCompat(t, sb, features, reason...); err != nil {
162+
t.Skipf(err.Error())
163+
}
164+
}
165+
166+
func HasFeatureCompat(t *testing.T, sb Sandbox, features map[string]struct{}, reason ...string) error {
159167
t.Helper()
160168
if len(reason) == 0 {
161169
t.Fatal("no reason provided")
@@ -172,6 +180,7 @@ func CheckFeatureCompat(t *testing.T, sb Sandbox, features map[string]struct{},
172180
}
173181
}
174182
if len(ereasons) > 0 {
175-
t.Skipf("%s worker can not currently run this test due to missing features (%s)", sb.Name(), strings.Join(ereasons, ", "))
183+
return errors.Errorf("%s worker can not currently run this test due to missing features (%s)", sb.Name(), strings.Join(ereasons, ", "))
176184
}
185+
return nil
177186
}

util/testutil/workers/features.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ var features = map[string]struct{}{
6161
func CheckFeatureCompat(t *testing.T, sb integration.Sandbox, reason ...string) {
6262
integration.CheckFeatureCompat(t, sb, features, reason...)
6363
}
64+
65+
func HasFeatureCompat(t *testing.T, sb integration.Sandbox, reason ...string) error {
66+
return integration.HasFeatureCompat(t, sb, features, reason...)
67+
}

0 commit comments

Comments
 (0)