Skip to content

Commit

Permalink
bugfix: alternate option now loads properly from .bertconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
sha1n committed Aug 6, 2024
1 parent b621bfa commit 0a800e2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/cli/main_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func loadSpec(cmd *cobra.Command, args []string) (spec api.BenchmarkSpec, err er
spec.Executions = executions
}

spec.Alternate = alternate
spec.Alternate = alternate || spec.Alternate

return spec, err
}
Expand Down
36 changes: 35 additions & 1 deletion internal/cli/main_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,31 @@ func TestWithMissingConfigFile(t *testing.T) {
runBenchmarkCommandWithPipedStdoutAndExpectPanicWith(t, nonExistingConfigArg)
}

func TestWithWdConfigDorFile(t *testing.T) {
func TestWithWDConfigFile(t *testing.T) {
wd, _ := os.Getwd()
os.Chdir("../../test/data") // expecting '../../test/data/.bertconfig' to be loaded
defer os.Chdir(wd)

expectedSpec, _ := specs.LoadSpec(itConfigFilePath)
expectedSpec.Executions = 1
expectedSpec.Alternate = false
command := newDummyCommandWith()

spec, err := loadSpec(command, []string{})

assert.NoError(t, err)
assert.Equal(t, expectedSpec, spec)
}


func TestWithWDConfigFileAndExecutionsOptionOverride(t *testing.T) {
wd, _ := os.Getwd()
os.Chdir("../../test/data") // expecting '../../test/data/.bertconfig' to be loaded
defer os.Chdir(wd)

expectedSpec, _ := specs.LoadSpec(itConfigFilePath)
expectedSpec.Executions = expectedSpec.Executions + rand.Intn(10)
expectedSpec.Alternate = false
command := newDummyCommandWith("--executions", fmt.Sprint(expectedSpec.Executions))

spec, err := loadSpec(command, []string{})
Expand All @@ -110,6 +128,22 @@ func TestWithWdConfigDorFile(t *testing.T) {
assert.Equal(t, expectedSpec, spec)
}

func TestWithWDConfigFileAndAlternateOptionOverride(t *testing.T) {
wd, _ := os.Getwd()
os.Chdir("../../test/data") // expecting '../../test/data/.bertconfig' to be loaded
defer os.Chdir(wd)

expectedSpec, _ := specs.LoadSpec(itConfigFilePath)
expectedSpec.Executions = 1
expectedSpec.Alternate = true
command := newDummyCommandWith("--alternate")

spec, err := loadSpec(command, []string{})

assert.NoError(t, err)
assert.Equal(t, expectedSpec, spec)
}

func TestWithInvalidConfigFile(t *testing.T) {
invalidConfig := "-c=../../test/data/invalid_config.yml"
runBenchmarkCommandWithPipedStdoutAndExpectPanicWith(t, invalidConfig)
Expand Down
1 change: 1 addition & 0 deletions test/data/.bertconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
alternate: false
executions: 1
scenarios:
- name: NAME
Expand Down

0 comments on commit 0a800e2

Please sign in to comment.