Skip to content

Commit

Permalink
test: add HasFeatureCompat helper
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jedevc committed Aug 4, 2023
1 parent b49a887 commit ca9bec9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion util/testutil/integration/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/google/shlex"
"github.com/moby/buildkit/util/bklog"
"github.com/pkg/errors"
)

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

func CheckFeatureCompat(t *testing.T, sb Sandbox, features map[string]struct{}, reason ...string) {
t.Helper()
if err := HasFeatureCompat(t, sb, features, reason...); err != nil {
t.Skipf(err.Error())
}
}

func HasFeatureCompat(t *testing.T, sb Sandbox, features map[string]struct{}, reason ...string) error {
t.Helper()
if len(reason) == 0 {
t.Fatal("no reason provided")
Expand All @@ -172,6 +180,7 @@ func CheckFeatureCompat(t *testing.T, sb Sandbox, features map[string]struct{},
}
}
if len(ereasons) > 0 {
t.Skipf("%s worker can not currently run this test due to missing features (%s)", sb.Name(), strings.Join(ereasons, ", "))
return errors.Errorf("%s worker can not currently run this test due to missing features (%s)", sb.Name(), strings.Join(ereasons, ", "))
}
return nil
}
4 changes: 4 additions & 0 deletions util/testutil/workers/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ var features = map[string]struct{}{
func CheckFeatureCompat(t *testing.T, sb integration.Sandbox, reason ...string) {
integration.CheckFeatureCompat(t, sb, features, reason...)
}

func HasFeatureCompat(t *testing.T, sb integration.Sandbox, reason ...string) error {
return integration.HasFeatureCompat(t, sb, features, reason...)
}

0 comments on commit ca9bec9

Please sign in to comment.