Skip to content

Commit 5a24932

Browse files
committed
Change comparators signature to use tig.T
Signed-off-by: apostasie <[email protected]>
1 parent b363856 commit 5a24932

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

mod/tigron/expect/comparators.go

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
*/
1616

1717
//revive:disable:package-comments // annoying false positive behavior
18-
//nolint:thelper // FIXME: remove when we move to tig.T
18+
1919
package expect
2020

2121
import (
2222
"encoding/json"
2323
"regexp"
24-
"testing"
2524

2625
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
2726
"github.com/containerd/nerdctl/mod/tigron/test"
@@ -30,7 +29,7 @@ import (
3029

3130
// All can be used as a parameter for expected.Output to group a set of comparators.
3231
func All(comparators ...test.Comparator) test.Comparator {
33-
return func(stdout string, t *testing.T) {
32+
return func(stdout string, t tig.T) {
3433
t.Helper()
3534

3635
for _, comparator := range comparators {
@@ -42,41 +41,51 @@ func All(comparators ...test.Comparator) test.Comparator {
4241
// Contains can be used as a parameter for expected.Output and ensures a comparison string is found contained in the
4342
// output.
4443
func Contains(compare string, more ...string) test.Comparator {
45-
return func(stdout string, t *testing.T) {
46-
t.Helper()
44+
return func(stdout string, testing tig.T) {
45+
testing.Helper()
4746

48-
assertive.Contains(assertive.WithFailLater(t), stdout, compare, "Inspecting output (contains)")
47+
assertive.Contains(assertive.WithFailLater(testing), stdout, compare, "Inspecting output (contains)")
4948

5049
for _, m := range more {
51-
assertive.Contains(assertive.WithFailLater(t), stdout, m, "Inspecting output (contains)")
50+
assertive.Contains(assertive.WithFailLater(testing), stdout, m, "Inspecting output (contains)")
5251
}
5352
}
5453
}
5554

5655
// DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in the output.
5756
func DoesNotContain(compare string, more ...string) test.Comparator {
58-
return func(stdout string, t *testing.T) {
59-
t.Helper()
57+
return func(stdout string, testing tig.T) {
58+
testing.Helper()
6059

61-
assertive.DoesNotContain(assertive.WithFailLater(t), stdout, compare, "Inspecting output (does not contain)")
60+
assertive.DoesNotContain(
61+
assertive.WithFailLater(testing),
62+
stdout,
63+
compare,
64+
"Inspecting output (does not contain)",
65+
)
6266

6367
for _, m := range more {
64-
assertive.DoesNotContain(assertive.WithFailLater(t), stdout, m, "Inspecting output (does not contain)")
68+
assertive.DoesNotContain(
69+
assertive.WithFailLater(testing),
70+
stdout,
71+
m,
72+
"Inspecting output (does not contain)",
73+
)
6574
}
6675
}
6776
}
6877

6978
// Equals is to be used for expected.Output to ensure it is exactly the output.
7079
func Equals(compare string) test.Comparator {
71-
return func(stdout string, t *testing.T) {
80+
return func(stdout string, t tig.T) {
7281
t.Helper()
7382
assertive.IsEqual(assertive.WithFailLater(t), stdout, compare, "Inspecting output (equals)")
7483
}
7584
}
7685

7786
// Match is to be used for expected.Output to ensure we match a regexp.
7887
func Match(reg *regexp.Regexp) test.Comparator {
79-
return func(stdout string, t *testing.T) {
88+
return func(stdout string, t tig.T) {
8089
t.Helper()
8190
assertive.Match(assertive.WithFailLater(t), stdout, reg, "Inspecting output (match)")
8291
}
@@ -85,14 +94,14 @@ func Match(reg *regexp.Regexp) test.Comparator {
8594
// JSON allows to verify that the output can be marshalled into T, and optionally can be further verified by a provided
8695
// method.
8796
func JSON[T any](obj T, verifier func(T, tig.T)) test.Comparator {
88-
return func(stdout string, t *testing.T) {
89-
t.Helper()
97+
return func(stdout string, testing tig.T) {
98+
testing.Helper()
9099

91100
err := json.Unmarshal([]byte(stdout), &obj)
92-
assertive.ErrorIsNil(assertive.WithSilentSuccess(t), err, "Unmarshalling JSON from stdout must succeed")
101+
assertive.ErrorIsNil(assertive.WithSilentSuccess(testing), err, "Unmarshalling JSON from stdout must succeed")
93102

94103
if verifier != nil && err == nil {
95-
verifier(obj, t)
104+
verifier(obj, testing)
96105
}
97106
}
98107
}

mod/tigron/test/funct.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package test
1818

19-
import "testing"
19+
import (
20+
"github.com/containerd/nerdctl/mod/tigron/tig"
21+
)
2022

2123
// An Evaluator is a function that decides whether a test should run or not.
2224
type Evaluator func(data Data, helpers Helpers) (bool, string)
@@ -30,7 +32,7 @@ type Butler func(data Data, helpers Helpers)
3032
// - move to tig.T
3133

3234
// A Comparator is the function signature to implement for the Output property of an Expected.
33-
type Comparator func(stdout string, t *testing.T)
35+
type Comparator func(stdout string, t tig.T)
3436

3537
// A Manager is the function signature meant to produce expectations for a command.
3638
type Manager func(data Data, helpers Helpers) *Expected

mod/tigron/test/helpers.go

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

2222
"github.com/containerd/nerdctl/mod/tigron/internal"
23+
"github.com/containerd/nerdctl/mod/tigron/tig"
2324
)
2425

2526
// This is the implementation of Helpers
@@ -60,8 +61,7 @@ func (help *helpersInternal) Capture(args ...string) string {
6061

6162
help.t.Helper()
6263
help.Command(args...).Run(&Expected{
63-
//nolint:thelper
64-
Output: func(stdout string, _ *testing.T) {
64+
Output: func(stdout string, _ tig.T) {
6565
ret = stdout
6666
},
6767
})

0 commit comments

Comments
 (0)