Remove testutils.Check(t, err) and replace it with require.NoError which gives a clearer error message and a full stacktrace

This commit is contained in:
David Dworken
2023-09-24 16:05:01 -07:00
parent c77d5a5424
commit 9fda54d4c2
7 changed files with 156 additions and 160 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/ddworken/hishtory/shared/testutils"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
)
type operation struct {
@ -79,11 +80,11 @@ func fuzzTest(t *testing.T, tester shellTester, input string) {
switchToDevice(&devices, op.device)
if op.cmd != "" {
_, err := tester.RunInteractiveShellRelaxed(t, op.cmd)
testutils.Check(t, err)
require.NoError(t, err)
}
if op.redactQuery != "" {
_, err := tester.RunInteractiveShellRelaxed(t, `HISHTORY_REDACT_FORCE=1 hishtory redact `+op.redactQuery)
testutils.Check(t, err)
require.NoError(t, err)
}
// Calculate the expected output of hishtory export
@ -111,7 +112,7 @@ func fuzzTest(t *testing.T, tester shellTester, input string) {
// Run hishtory export and check the output
out, err := tester.RunInteractiveShellRelaxed(t, `hishtory export -export -pipefail`)
testutils.Check(t, err)
require.NoError(t, err)
expectedOutput := keyToCommands[op.device.key]
if diff := cmp.Diff(expectedOutput, out); diff != "" {
t.Fatalf("hishtory export mismatch for input=%#v key=%s (-expected +got):\n%s\nout=%#v", input, op.device.key, diff, out)
@ -122,7 +123,7 @@ func fuzzTest(t *testing.T, tester shellTester, input string) {
for _, op := range ops {
switchToDevice(&devices, op.device)
out, err := tester.RunInteractiveShellRelaxed(t, `hishtory export -export -pipefail`)
testutils.Check(t, err)
require.NoError(t, err)
expectedOutput := keyToCommands[op.device.key]
if diff := cmp.Diff(expectedOutput, out); diff != "" {
t.Fatalf("hishtory export mismatch for key=%s (-expected +got):\n%s\nout=%#v", op.device.key, diff, out)