diff --git a/CHANGELOG.md b/CHANGELOG.md index e77c675c..873e8e41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # v1.2.0 - - Add `interval` option for `retries` which allows to execute a retry after a given period of time. I.e. `interval: 50ms` +- Add reading envrionment variables from shell +- Add `interval` option for `retries` which allows to execute a retry after a given period of time. I.e. `interval: 50ms` # v1.1.0 diff --git a/docs/manual.md b/docs/manual.md index f5d8e5c8..724d2f92 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -33,6 +33,7 @@ config: # Config for all tests dir: /tmp #Set working directory env: # Environment variables KEY: global + PATH_FROM_SHELL: ${PATH} # Read an env variable from the current shell timeout: 5000 # Timeout in ms retries: 2 # Define retries for each test diff --git a/pkg/cmd/command_test.go b/pkg/cmd/command_test.go index 37f78cb9..89b56561 100644 --- a/pkg/cmd/command_test.go +++ b/pkg/cmd/command_test.go @@ -70,7 +70,7 @@ func TestCommand_AddEnvWithShellVariable(t *testing.T) { os.Setenv(TestEnvKey, "test from shell") defer os.Unsetenv(TestEnvKey) - c := NewCommand("echo $SOME_KEY") + c := NewCommand(getCommand()) c.AddEnv("SOME_KEY", fmt.Sprintf("${%s}", TestEnvKey)) err := c.Execute() @@ -89,7 +89,7 @@ func TestCommand_AddMultipleEnvWithShellVariable(t *testing.T) { os.Unsetenv(TestEnvKeyName) }() - c := NewCommand("echo $SOME_KEY") + c := NewCommand(getCommand()) envValue := fmt.Sprintf("Hello ${%s}, I am ${%s}", TestEnvKeyPlanet, TestEnvKeyName) c.AddEnv("SOME_KEY", envValue) @@ -99,6 +99,14 @@ func TestCommand_AddMultipleEnvWithShellVariable(t *testing.T) { assert.Equal(t, "Hello world, I am Simon", c.Stdout()) } +func getCommand() string { + command := "echo $SOME_KEY" + if runtime.GOOS == "windows" { + command = "echo %SOME_KEY%" + } + return command +} + func TestCommand_SetTimeoutMS_DefaultTimeout(t *testing.T) { c := NewCommand("echo test") c.SetTimeoutMS(0)