14
14
limitations under the License.
15
15
*/
16
16
17
+ //revive:disable:package-comments // annoying false positive behavior
18
+ //nolint:thelper // FIXME: remove when we move to tig.T
17
19
package expect
18
20
19
21
import (
20
- "encoding/hex"
21
- "fmt"
22
22
"regexp"
23
- "strings"
24
23
"testing"
25
24
26
25
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
@@ -29,7 +28,6 @@ import (
29
28
30
29
// All can be used as a parameter for expected.Output to group a set of comparators.
31
30
func All (comparators ... test.Comparator ) test.Comparator {
32
- //nolint:thelper
33
31
return func (stdout , info string , t * testing.T ) {
34
32
t .Helper ()
35
33
@@ -39,57 +37,35 @@ func All(comparators ...test.Comparator) test.Comparator {
39
37
}
40
38
}
41
39
42
- // Contains can be used as a parameter for expected.Output and ensures a comparison string
43
- // is found contained in the output.
40
+ // Contains can be used as a parameter for expected.Output and ensures a comparison string is found contained in the
41
+ // output.
44
42
func Contains (compare string ) test.Comparator {
45
- //nolint:thelper
46
43
return func (stdout , info string , t * testing.T ) {
47
44
t .Helper ()
48
- assertive .Check (t , strings .Contains (stdout , compare ),
49
- fmt .Sprintf ("Output does not contain: %q" , compare ),
50
- info )
45
+ assertive .Contains (assertive .WithFailLater (t ), stdout , compare , info )
51
46
}
52
47
}
53
48
54
- // DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in
55
- // the output.
49
+ // DoesNotContain is to be used for expected.Output to ensure a comparison string is NOT found in the output.
56
50
func DoesNotContain (compare string ) test.Comparator {
57
- //nolint:thelper
58
51
return func (stdout , info string , t * testing.T ) {
59
52
t .Helper ()
60
- assertive .Check (t , ! strings .Contains (stdout , compare ),
61
- fmt .Sprintf ("Output should not contain: %q" , compare ), info )
53
+ assertive .DoesNotContain (assertive .WithFailLater (t ), stdout , compare , info )
62
54
}
63
55
}
64
56
65
57
// Equals is to be used for expected.Output to ensure it is exactly the output.
66
58
func Equals (compare string ) test.Comparator {
67
- //nolint:thelper
68
59
return func (stdout , info string , t * testing.T ) {
69
60
t .Helper ()
70
-
71
- hexdump := hex .Dump ([]byte (stdout ))
72
- assertive .Check (
73
- t ,
74
- compare == stdout ,
75
- fmt .Sprintf ("Output is not equal to: %q" , compare ),
76
- "\n " + hexdump ,
77
- info ,
78
- )
61
+ assertive .IsEqual (assertive .WithFailLater (t ), stdout , compare , info )
79
62
}
80
63
}
81
64
82
65
// Match is to be used for expected.Output to ensure we match a regexp.
83
- // Provisional - expected use, but have not seen it so far.
84
66
func Match (reg * regexp.Regexp ) test.Comparator {
85
- //nolint:thelper
86
67
return func (stdout , info string , t * testing.T ) {
87
68
t .Helper ()
88
- assertive .Check (
89
- t ,
90
- reg .MatchString (stdout ),
91
- fmt .Sprintf ("Output does not match: %q" , reg .String ()),
92
- info ,
93
- )
69
+ assertive .Match (assertive .WithFailLater (t ), stdout , reg , info )
94
70
}
95
71
}
0 commit comments