Skip to content

Commit

Permalink
Fix inconsistency in env variables names (#2140)
Browse files Browse the repository at this point in the history
* lib: make consistent env vars names

* config: add unit tests
  • Loading branch information
yorugac authored Oct 4, 2021
1 parent 75d30e6 commit 586f0e5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
43 changes: 39 additions & 4 deletions cmd/config_consolidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ func verifyConstLoopingVUs(vus null.Int, duration time.Duration) func(t *testing
}
}

func verifyExternallyExecuted(scenarioName string, vus null.Int, duration time.Duration) func(t *testing.T, c Config) {
return func(t *testing.T, c Config) {
exec := c.Scenarios[scenarioName]
require.NotEmpty(t, exec)
require.IsType(t, executor.ExternallyControlledConfig{}, exec)
ecc, ok := exec.(executor.ExternallyControlledConfig)
require.True(t, ok)
assert.Equal(t, vus, ecc.VUs)
assert.Equal(t, types.NullDurationFrom(duration), ecc.Duration)
assert.Equal(t, vus, ecc.MaxVUs) // MaxVUs defaults to VUs unless specified
}
}

func verifyRampingVUs(startVus null.Int, stages []executor.Stage) func(t *testing.T, c Config) {
return func(t *testing.T, c Config) {
exec := c.Scenarios[lib.DefaultScenarioName]
Expand Down Expand Up @@ -181,7 +194,7 @@ func resetStickyGlobalVars() {
type exp struct {
cliParseError bool
cliReadError bool
consolidationError bool
consolidationError bool // Note: consolidationError includes validation errors from envconfig.Process()
derivationError bool
validationErrors bool
logWarning bool
Expand Down Expand Up @@ -234,7 +247,7 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase {
{opts{cli: []string{"--vus", "10", "-i", "6"}}, exp{validationErrors: true}, verifySharedIters(I(10), I(6))},
{opts{cli: []string{"-s", "10s:5", "-s", "10s:"}}, exp{validationErrors: true}, nil},
{opts{fs: defaultConfig(`{"stages": [{"duration": "20s"}], "vus": 10}`)}, exp{validationErrors: true}, nil},
// These should emit a consolidation error
// These should emit a derivation error
{opts{cli: []string{"-u", "2", "-d", "10s", "-s", "10s:20"}}, exp{derivationError: true}, nil},
{opts{cli: []string{"-u", "3", "-i", "5", "-s", "10s:20"}}, exp{derivationError: true}, nil},
{opts{cli: []string{"-u", "3", "-d", "0"}}, exp{derivationError: true}, nil},
Expand Down Expand Up @@ -360,7 +373,15 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase {
assert.Equal(t, types.NullDurationFrom(10*time.Second), clvc.GracefulStop)
},
},
// TODO: test the externally controlled executor
{
opts{
fs: defaultConfig(`{"scenarios": { "def": {
"executor": "externally-controlled", "vus": 15, "duration": "2h"
}}}`),
},
exp{},
verifyExternallyExecuted("def", I(15), 2*time.Hour),
},
// TODO: test execution-segment

// Just in case, verify that no options will result in the same 1 vu 1 iter config
Expand Down Expand Up @@ -488,7 +509,21 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase {
}, c.Options.DNS)
},
},

{
opts{env: []string{"K6_NO_SETUP=true", "K6_NO_TEARDOWN=false"}},
exp{},
func(t *testing.T, c Config) {
assert.Equal(t, null.BoolFrom(true), c.Options.NoSetup)
assert.Equal(t, null.BoolFrom(false), c.Options.NoTeardown)
},
},
{
opts{env: []string{"K6_NO_SETUP=false", "K6_NO_TEARDOWN=bool"}},
exp{
consolidationError: true,
},
nil,
},
// TODO: test for differences between flagsets
// TODO: more tests in general, especially ones not related to execution parameters...
}
Expand Down
4 changes: 2 additions & 2 deletions lib/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ type Options struct {
ExecutionSegmentSequence *ExecutionSegmentSequence `json:"executionSegmentSequence" ignored:"true"`

// Timeouts for the setup() and teardown() functions
NoSetup null.Bool `json:"noSetup" envconfig:"NO_SETUP"`
NoSetup null.Bool `json:"noSetup" envconfig:"K6_NO_SETUP"`
SetupTimeout types.NullDuration `json:"setupTimeout" envconfig:"K6_SETUP_TIMEOUT"`
NoTeardown null.Bool `json:"noTeardown" envconfig:"NO_TEARDOWN"`
NoTeardown null.Bool `json:"noTeardown" envconfig:"K6_NO_TEARDOWN"`
TeardownTimeout types.NullDuration `json:"teardownTimeout" envconfig:"K6_TEARDOWN_TIMEOUT"`

// Limit HTTP requests per second.
Expand Down
10 changes: 10 additions & 0 deletions lib/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,16 @@ func TestOptionsEnv(t *testing.T) {
"": null.Int{},
"123": null.IntFrom(123),
},
{"NoSetup", "K6_NO_SETUP"}: {
"": null.Bool{},
"true": null.BoolFrom(true),
"false": null.BoolFrom(false),
},
{"NoTeardown", "K6_NO_TEARDOWN"}: {
"": null.Bool{},
"true": null.BoolFrom(true),
"false": null.BoolFrom(false),
},
{"InsecureSkipTLSVerify", "K6_INSECURE_SKIP_TLS_VERIFY"}: {
"": null.Bool{},
"true": null.BoolFrom(true),
Expand Down

0 comments on commit 586f0e5

Please sign in to comment.