@@ -11,7 +11,6 @@ import (
11
11
"strings"
12
12
"testing"
13
13
14
- "github.com/google/go-cmp/cmp"
15
14
"github.com/google/uuid"
16
15
"github.com/stretchr/testify/require"
17
16
@@ -96,32 +95,32 @@ ExtractCommandPathsLoop:
96
95
97
96
// TestGoldenFile will test the given bytes slice input against the
98
97
// 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 {
103
100
t .Fatal ("no output" )
104
101
}
105
102
106
103
for k , v := range replacements {
107
- got = bytes .ReplaceAll (got , []byte (k ), []byte (v ))
104
+ actual = bytes .ReplaceAll (actual , []byte (k ), []byte (v ))
108
105
}
109
106
110
- got = normalizeGoldenFile (t , got )
107
+ actual = normalizeGoldenFile (t , actual )
111
108
goldenPath := filepath .Join ("testdata" , strings .ReplaceAll (fileName , " " , "_" )+ ".golden" )
112
109
if * UpdateGoldenFiles {
113
110
t .Logf ("update golden file for: %q: %s" , fileName , goldenPath )
114
- err := os .WriteFile (goldenPath , got , 0o600 )
111
+ err := os .WriteFile (goldenPath , actual , 0o600 )
115
112
require .NoError (t , err , "update golden file" )
116
113
}
117
114
118
- want , err := os .ReadFile (goldenPath )
115
+ expected , err := os .ReadFile (goldenPath )
119
116
require .NoError (t , err , "read golden file, run \" make update-golden-files\" and commit the changes" )
120
117
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
+ )
125
124
}
126
125
127
126
// normalizeGoldenFile replaces any strings that are system or timing dependent
0 commit comments