Skip to content

Commit 4ad52bc

Browse files
committed
Migrate away from assert to internal assertive
Signed-off-by: apostasie <[email protected]>
1 parent 7cc4257 commit 4ad52bc

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

mod/tigron/expect/comparators.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import (
2222
"strings"
2323
"testing"
2424

25-
"gotest.tools/v3/assert"
26-
25+
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
2726
"github.com/containerd/nerdctl/mod/tigron/test"
2827
)
2928

@@ -45,7 +44,7 @@ func Contains(compare string) test.Comparator {
4544
//nolint:thelper
4645
return func(stdout, info string, t *testing.T) {
4746
t.Helper()
48-
assert.Check(t, strings.Contains(stdout, compare),
47+
assertive.Check(t, strings.Contains(stdout, compare),
4948
fmt.Sprintf("Output does not contain: %q", compare)+info)
5049
}
5150
}
@@ -56,8 +55,8 @@ func DoesNotContain(compare string) test.Comparator {
5655
//nolint:thelper
5756
return func(stdout, info string, t *testing.T) {
5857
t.Helper()
59-
assert.Check(t, !strings.Contains(stdout, compare),
60-
fmt.Sprintf("Output does contain: %q", compare)+info)
58+
assertive.Check(t, !strings.Contains(stdout, compare),
59+
fmt.Sprintf("Output should not contain: %q", compare)+info)
6160
}
6261
}
6362

@@ -66,7 +65,11 @@ func Equals(compare string) test.Comparator {
6665
//nolint:thelper
6766
return func(stdout, info string, t *testing.T) {
6867
t.Helper()
69-
assert.Equal(t, compare, stdout, info)
68+
assertive.Check(
69+
t,
70+
compare == stdout,
71+
fmt.Sprintf("Output is not equal to: %q", compare)+info,
72+
)
7073
}
7174
}
7275

@@ -76,6 +79,11 @@ func Match(reg *regexp.Regexp) test.Comparator {
7679
//nolint:thelper
7780
return func(stdout, info string, t *testing.T) {
7881
t.Helper()
79-
assert.Check(t, reg.MatchString(stdout), "Output does not match: "+reg.String(), info)
82+
assertive.Check(
83+
t,
84+
reg.MatchString(stdout),
85+
fmt.Sprintf("Output does not match: %q", reg.String()),
86+
info,
87+
)
8088
}
8189
}

mod/tigron/test/case.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"slices"
2121
"testing"
2222

23-
"gotest.tools/v3/assert"
23+
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
2424
)
2525

2626
// Case describes an entire test-case, including data, setup and cleanup routines, command and
@@ -72,16 +72,16 @@ func (test *Case) Run(t *testing.T) {
7272
testRun := func(subT *testing.T) {
7373
subT.Helper()
7474

75-
assert.Assert(subT, test.t == nil, "You cannot run a test multiple times")
75+
assertive.True(subT, test.t == nil, "You cannot run a test multiple times")
7676

7777
// Attach testing.T
7878
test.t = subT
79-
assert.Assert(
79+
assertive.True(
8080
test.t,
8181
test.Description != "" || test.parent == nil,
8282
"A test description cannot be empty",
8383
)
84-
assert.Assert(test.t, test.Command == nil || test.Expected != nil,
84+
assertive.True(test.t, test.Command == nil || test.Expected != nil,
8585
"Expectations for a test command cannot be nil. You may want to use Setup instead.")
8686

8787
// Ensure we have env

mod/tigron/test/command.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import (
2828

2929
"golang.org/x/sync/errgroup"
3030
"golang.org/x/term"
31-
"gotest.tools/v3/assert"
3231
"gotest.tools/v3/icmd"
3332

33+
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
3434
"github.com/containerd/nerdctl/mod/tigron/test/internal"
3535
"github.com/containerd/nerdctl/mod/tigron/test/internal/pty"
3636
)
@@ -215,19 +215,19 @@ func (gc *GenericCommand) Run(expect *Expected) {
215215
// success, or a timeout.
216216
case internal.ExitCodeGenericFail:
217217
// ExitCodeGenericFail means we expect an error (excluding timeout).
218-
assert.Assert(gc.t, result.ExitCode != 0,
218+
assertive.True(gc.t, result.ExitCode != 0,
219219
"Expected exit code to be different than 0\n"+debug)
220220
case internal.ExitCodeTimeout:
221-
assert.Assert(gc.t, expect.ExitCode == internal.ExitCodeTimeout,
221+
assertive.True(gc.t, expect.ExitCode == internal.ExitCodeTimeout,
222222
"Command unexpectedly timed-out\n"+debug)
223223
default:
224-
assert.Assert(gc.t, expect.ExitCode == result.ExitCode,
224+
assertive.True(gc.t, expect.ExitCode == result.ExitCode,
225225
fmt.Sprintf("Expected exit code: %d\n", expect.ExitCode)+debug)
226226
}
227227

228228
// Range through the expected errors and confirm they are seen on stderr
229229
for _, expectErr := range expect.Errors {
230-
assert.Assert(gc.t, strings.Contains(gc.rawStdErr, expectErr.Error()),
230+
assertive.True(gc.t, strings.Contains(gc.rawStdErr, expectErr.Error()),
231231
fmt.Sprintf("Expected error: %q to be found in stderr\n", expectErr.Error())+debug)
232232
}
233233

0 commit comments

Comments
 (0)