Skip to content

Commit 8568f23

Browse files
committed
version placeholder in golden file
1 parent a650ce9 commit 8568f23

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

tests/golden/v/version.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rules version 1.0.11
1+
rules version <VERSION_PLACEHOLDER>

tests/golden_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,16 @@ func TestGoldenFiles(t *testing.T) {
250250
t.Errorf("Output does not match golden file with placeholders.\nCommand: %s\nExpected:\n%s\n\nGot:\n%s",
251251
cmd, expected, actual)
252252
}
253+
} else if strings.Contains(expected, "<VERSION_PLACEHOLDER>") {
254+
// Match version output with placeholder
255+
// Replace the actual version in the output with the placeholder and compare
256+
actualNormalized := actual
257+
// Look for a line like 'rules version x.y.z' and replace the version with the placeholder
258+
actualNormalized = versionPlaceholderNormalize(actualNormalized)
259+
if actualNormalized != expected {
260+
t.Errorf("Output does not match golden file with version placeholder.\nCommand: %s\nExpected:\n%s\n\nGot:\n%s",
261+
cmd, expected, actual)
262+
}
253263
} else {
254264
// Standard equality check for other files
255265
if actual != expected {
@@ -261,6 +271,18 @@ func TestGoldenFiles(t *testing.T) {
261271
}
262272
}
263273

274+
// versionPlaceholderNormalize replaces the version number in the version output with the placeholder
275+
func versionPlaceholderNormalize(s string) string {
276+
lines := strings.Split(s, "\n")
277+
for i, line := range lines {
278+
if strings.HasPrefix(line, "rules version ") {
279+
// Replace everything after 'rules version '
280+
lines[i] = "rules version <VERSION_PLACEHOLDER>"
281+
}
282+
}
283+
return strings.Join(lines, "\n")
284+
}
285+
264286
// copyFile copies a file from src to dst
265287
func copyFile(src, dst string) error {
266288
sourceFile, err := os.Open(src)

0 commit comments

Comments
 (0)