Skip to content

Commit 88b9c53

Browse files
committed
Assertive enhancements
This brings a set of enhancements to assertive: - function name simplifications - generics-ifying of some functions that can be used on comparables - additional methods (Match, DoesNotMatch) - debugging output is made clear, along with OCS8 link to the test file - all methods can now elect to Fail later instead of FailNow - Check method is removed (^ because of above) - all methods can now elect to silence output on success Other Tigron files are updated to adopt these changes: - method names update - comparators move away from Check and now fully leverages assertive This also adds a large number of tests for assertive, leveraging mimicry. Signed-off-by: apostasie <[email protected]>
1 parent ed47d87 commit 88b9c53

File tree

6 files changed

+386
-160
lines changed

6 files changed

+386
-160
lines changed

mod/tigron/expect/comparators.go

+9-33
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
limitations under the License.
1515
*/
1616

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

1921
import (
20-
"encoding/hex"
21-
"fmt"
2222
"regexp"
23-
"strings"
2423
"testing"
2524

2625
"github.com/containerd/nerdctl/mod/tigron/internal/assertive"
@@ -29,7 +28,6 @@ import (
2928

3029
// All can be used as a parameter for expected.Output to group a set of comparators.
3130
func All(comparators ...test.Comparator) test.Comparator {
32-
//nolint:thelper
3331
return func(stdout, info string, t *testing.T) {
3432
t.Helper()
3533

@@ -39,57 +37,35 @@ func All(comparators ...test.Comparator) test.Comparator {
3937
}
4038
}
4139

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.
4442
func Contains(compare string) test.Comparator {
45-
//nolint:thelper
4643
return func(stdout, info string, t *testing.T) {
4744
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)
5146
}
5247
}
5348

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.
5650
func DoesNotContain(compare string) test.Comparator {
57-
//nolint:thelper
5851
return func(stdout, info string, t *testing.T) {
5952
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)
6254
}
6355
}
6456

6557
// Equals is to be used for expected.Output to ensure it is exactly the output.
6658
func Equals(compare string) test.Comparator {
67-
//nolint:thelper
6859
return func(stdout, info string, t *testing.T) {
6960
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)
7962
}
8063
}
8164

8265
// 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.
8466
func Match(reg *regexp.Regexp) test.Comparator {
85-
//nolint:thelper
8667
return func(stdout, info string, t *testing.T) {
8768
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)
9470
}
9571
}

0 commit comments

Comments
 (0)