15
15
*/
16
16
17
17
//revive:disable:package-comments // annoying false positive behavior
18
- //nolint:thelper // FIXME: remove when we move to tig.T
18
+
19
19
package expect
20
20
21
21
import (
22
22
"encoding/json"
23
23
"regexp"
24
- "testing"
25
24
26
25
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
27
26
"github.com/containerd/nerdctl/mod/tigron/test"
@@ -30,7 +29,7 @@ import (
30
29
31
30
// All can be used as a parameter for expected.Output to group a set of comparators.
32
31
func All (comparators ... test.Comparator ) test.Comparator {
33
- return func (stdout string , t * testing .T ) {
32
+ return func (stdout string , t tig .T ) {
34
33
t .Helper ()
35
34
36
35
for _ , comparator := range comparators {
@@ -42,41 +41,51 @@ func All(comparators ...test.Comparator) test.Comparator {
42
41
// Contains can be used as a parameter for expected.Output and ensures a comparison string is found contained in the
43
42
// output.
44
43
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 ()
47
46
48
- assertive .Contains (assertive .WithFailLater (t ), stdout , compare , "Inspecting output (contains)" )
47
+ assertive .Contains (assertive .WithFailLater (testing ), stdout , compare , "Inspecting output (contains)" )
49
48
50
49
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)" )
52
51
}
53
52
}
54
53
}
55
54
56
55
// DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in the output.
57
56
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 ()
60
59
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
+ )
62
66
63
67
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
+ )
65
74
}
66
75
}
67
76
}
68
77
69
78
// Equals is to be used for expected.Output to ensure it is exactly the output.
70
79
func Equals (compare string ) test.Comparator {
71
- return func (stdout string , t * testing .T ) {
80
+ return func (stdout string , t tig .T ) {
72
81
t .Helper ()
73
82
assertive .IsEqual (assertive .WithFailLater (t ), stdout , compare , "Inspecting output (equals)" )
74
83
}
75
84
}
76
85
77
86
// Match is to be used for expected.Output to ensure we match a regexp.
78
87
func Match (reg * regexp.Regexp ) test.Comparator {
79
- return func (stdout string , t * testing .T ) {
88
+ return func (stdout string , t tig .T ) {
80
89
t .Helper ()
81
90
assertive .Match (assertive .WithFailLater (t ), stdout , reg , "Inspecting output (match)" )
82
91
}
@@ -85,14 +94,14 @@ func Match(reg *regexp.Regexp) test.Comparator {
85
94
// JSON allows to verify that the output can be marshalled into T, and optionally can be further verified by a provided
86
95
// method.
87
96
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 ()
90
99
91
100
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" )
93
102
94
103
if verifier != nil && err == nil {
95
- verifier (obj , t )
104
+ verifier (obj , testing )
96
105
}
97
106
}
98
107
}
0 commit comments