1515*/
1616
1717//revive:disable:package-comments // annoying false positive behavior
18- //nolint:thelper // FIXME: remove when we move to tig.T
18+
1919package expect
2020
2121import (
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.
3231func 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.
4443func 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.
5756func 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.
7079func 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.
7887func 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.
8796func 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}
0 commit comments