Skip to content

Commit

Permalink
Merge pull request #462 from nextmv-io/merschformann/configurable-gol…
Browse files Browse the repository at this point in the history
…den-extension

Allows control over golden file extension
  • Loading branch information
merschformann authored Dec 16, 2024
2 parents 8796b90 + 7da66db commit 7313546
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion golden/bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ func BashTestFile(
script string,
bashConfig BashConfig,
) {
goldenFilePath := script + goldenExtension
ext := goldenExtension
if bashConfig.GoldenExtension != "" {
ext = bashConfig.GoldenExtension
}
goldenFilePath := script + ext
// Function run by the test.
f := func(t *testing.T) {
// Make script path absolute to avoid issues with custom working
Expand Down
6 changes: 6 additions & 0 deletions golden/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type Config struct {
CompareConfig CompareConfig
// OutputProcessConfig defines how to process the output before comparison.
OutputProcessConfig OutputProcessConfig
// GoldenExtension is the file extension to use for the golden file. If not
// provided, then the default extension (.golden) is used.
GoldenExtension string
// SkipGoldenComparison skips the comparison against the golden file.
SkipGoldenComparison bool
// ExitCode defines the expected exit code of the command.
Expand Down Expand Up @@ -68,6 +71,9 @@ type BashConfig struct {
DisplayStderr bool
// OutputProcessConfig defines how to process the output before comparison.
OutputProcessConfig OutputProcessConfig
// GoldenExtension is the file extension to use for the golden file. If not
// provided, then the default extension (.golden) is used.
GoldenExtension string
// Envs specifies the environment variables to set for execution.
Envs [][2]string
// PostProcessFunctions defines a list of functions to be executed after the bash
Expand Down
6 changes: 5 additions & 1 deletion golden/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ func comparison(
) {
var err error

goldenPath := inputPath + goldenExtension
ext := goldenExtension
if config.GoldenExtension != "" {
ext = config.GoldenExtension
}
goldenPath := inputPath + ext
if config.OutputProcessConfig.RelativeDestination != "" {
goldenPath = filepath.Join(
config.OutputProcessConfig.RelativeDestination,
Expand Down

0 comments on commit 7313546

Please sign in to comment.