Skip to content

Commit

Permalink
fix: Update multienv_step_runner Env Var Parsing Logic (#2351) (#2354)
Browse files Browse the repository at this point in the history
* Update multienv_step_runner Env Var Parsing Logic

* Update multienv_step_runner.go to split only on the first = character
* Add affirmative and failing test cases

* Run gofmt
  • Loading branch information
Austin Sherron authored Jul 27, 2022
1 parent e0e29bd commit 6227b56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/core/runtime/multienv_step_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (r *MultiEnvStepRunner) Run(ctx command.ProjectContext, command string, pat
var sb strings.Builder
sb.WriteString("Dynamic environment variables added:\n")
for _, item := range envVars {
nameValue := strings.Split(item, "=")
nameValue := strings.SplitN(item, "=", 2)
if len(nameValue) == 2 {
envs[nameValue[0]] = nameValue[1]
sb.WriteString(nameValue[0])
Expand Down
10 changes: 10 additions & 0 deletions server/core/runtime/multienv_step_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func TestMultiEnvStepRunner_Run(t *testing.T) {
ExpOut: "Dynamic environment variables added:\nTF_VAR_REPODEFINEDVARIABLE_ONE\n",
Version: "v1.2.3",
},
{
Command: `echo 'TF_VAR_REPODEFINEDVARIABLE_TWO=value=1='`,
ExpOut: "Dynamic environment variables added:\nTF_VAR_REPODEFINEDVARIABLE_TWO\n",
Version: "v1.2.3",
},
{
Command: `echo 'TF_VAR_REPODEFINEDVARIABLE_NO_VALUE'`,
ExpErr: "Invalid environment variable definition: TF_VAR_REPODEFINEDVARIABLE_NO_VALUE",
Version: "v1.2.3",
},
}
RegisterMockTestingT(t)
tfClient := mocks.NewMockClient()
Expand Down

0 comments on commit 6227b56

Please sign in to comment.