Skip to content

Commit 7da66db

Browse files
committed
Allowing the user to control golden extension
1 parent 8796b90 commit 7da66db

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

golden/bash.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ func BashTestFile(
6565
script string,
6666
bashConfig BashConfig,
6767
) {
68-
goldenFilePath := script + goldenExtension
68+
ext := goldenExtension
69+
if bashConfig.GoldenExtension != "" {
70+
ext = bashConfig.GoldenExtension
71+
}
72+
goldenFilePath := script + ext
6973
// Function run by the test.
7074
f := func(t *testing.T) {
7175
// Make script path absolute to avoid issues with custom working

golden/config.go

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ type Config struct {
2727
CompareConfig CompareConfig
2828
// OutputProcessConfig defines how to process the output before comparison.
2929
OutputProcessConfig OutputProcessConfig
30+
// GoldenExtension is the file extension to use for the golden file. If not
31+
// provided, then the default extension (.golden) is used.
32+
GoldenExtension string
3033
// SkipGoldenComparison skips the comparison against the golden file.
3134
SkipGoldenComparison bool
3235
// ExitCode defines the expected exit code of the command.
@@ -68,6 +71,9 @@ type BashConfig struct {
6871
DisplayStderr bool
6972
// OutputProcessConfig defines how to process the output before comparison.
7073
OutputProcessConfig OutputProcessConfig
74+
// GoldenExtension is the file extension to use for the golden file. If not
75+
// provided, then the default extension (.golden) is used.
76+
GoldenExtension string
7177
// Envs specifies the environment variables to set for execution.
7278
Envs [][2]string
7379
// PostProcessFunctions defines a list of functions to be executed after the bash

golden/file.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ func comparison(
156156
) {
157157
var err error
158158

159-
goldenPath := inputPath + goldenExtension
159+
ext := goldenExtension
160+
if config.GoldenExtension != "" {
161+
ext = config.GoldenExtension
162+
}
163+
goldenPath := inputPath + ext
160164
if config.OutputProcessConfig.RelativeDestination != "" {
161165
goldenPath = filepath.Join(
162166
config.OutputProcessConfig.RelativeDestination,

0 commit comments

Comments
 (0)