Skip to content

Commit b8c4ab8

Browse files
committed
revert
1 parent 8d8689d commit b8c4ab8

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

cli/clitest/golden.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strings"
1212
"testing"
1313

14-
"github.com/google/go-cmp/cmp"
1514
"github.com/google/uuid"
1615
"github.com/stretchr/testify/require"
1716

@@ -96,32 +95,32 @@ ExtractCommandPathsLoop:
9695

9796
// TestGoldenFile will test the given bytes slice input against the
9897
// golden file with the given file name, optionally using the given replacements.
99-
func TestGoldenFile(t *testing.T, fileName string, got []byte, replacements map[string]string) {
100-
t.Helper()
101-
102-
if len(got) == 0 {
98+
func TestGoldenFile(t *testing.T, fileName string, actual []byte, replacements map[string]string) {
99+
if len(actual) == 0 {
103100
t.Fatal("no output")
104101
}
105102

106103
for k, v := range replacements {
107-
got = bytes.ReplaceAll(got, []byte(k), []byte(v))
104+
actual = bytes.ReplaceAll(actual, []byte(k), []byte(v))
108105
}
109106

110-
got = normalizeGoldenFile(t, got)
107+
actual = normalizeGoldenFile(t, actual)
111108
goldenPath := filepath.Join("testdata", strings.ReplaceAll(fileName, " ", "_")+".golden")
112109
if *UpdateGoldenFiles {
113110
t.Logf("update golden file for: %q: %s", fileName, goldenPath)
114-
err := os.WriteFile(goldenPath, got, 0o600)
111+
err := os.WriteFile(goldenPath, actual, 0o600)
115112
require.NoError(t, err, "update golden file")
116113
}
117114

118-
want, err := os.ReadFile(goldenPath)
115+
expected, err := os.ReadFile(goldenPath)
119116
require.NoError(t, err, "read golden file, run \"make update-golden-files\" and commit the changes")
120117

121-
want = normalizeGoldenFile(t, want)
122-
if diff := cmp.Diff(string(want), string(got)); diff != "" {
123-
require.Failf(t, "golden file mismatch, run \"make update-golden-files\", verify and commit the changes", "%s: diff (-want +got)\n%s", goldenPath, diff)
124-
}
118+
expected = normalizeGoldenFile(t, expected)
119+
require.Equal(
120+
t, string(expected), string(actual),
121+
"golden file mismatch: %s, run \"make update-golden-files\", verify and commit the changes",
122+
goldenPath,
123+
)
125124
}
126125

127126
// normalizeGoldenFile replaces any strings that are system or timing dependent

0 commit comments

Comments
 (0)