Skip to content

Commit

Permalink
fix(venom): env variables with equal sign (#721)
Browse files Browse the repository at this point in the history
* fix env variables with equal sign

Signed-off-by: Bram.Cautaerts <[email protected]>

* added unit test for env vars

Signed-off-by: Bram.Cautaerts <[email protected]>

* change to SplitN

Signed-off-by: Bram.Cautaerts <[email protected]>

---------

Signed-off-by: Bram.Cautaerts <[email protected]>
Co-authored-by: Bram.Cautaerts <[email protected]>
  • Loading branch information
bramca and Bram.Cautaerts authored Sep 28, 2023
1 parent 408bcdf commit a95b2a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/venom/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func initFromEnv(environ []string) ([]string, error) {

for _, env := range environ {
if strings.HasPrefix(env, "VENOM_VAR_") {
tuple := strings.Split(env, "=")
tuple := strings.SplitN(env, "=", 2)
k := strings.TrimPrefix(tuple[0], "VENOM_VAR_")
variables = append(variables, fmt.Sprintf("%v=%v", k, cast(tuple[1])))
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/venom/run/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ func Test_mergeVariables(t *testing.T) {
}

func Test_initFromEnv(t *testing.T) {
env := []string{`VENOM_VAR_a=1`, `VENOM_VAR_b="B"`, `VENOM_VAR_c=[1,2,3]`}
env := []string{`VENOM_VAR_a=1`, `VENOM_VAR_b="B"`, `VENOM_VAR_c=[1,2,3]`, `VENOM_VAR_d="e=f"`}
found, err := initFromEnv(env)
require.NoError(t, err)
require.Equal(t, 3, len(found))
require.Equal(t, 4, len(found))
var nb int
for i := range found {
if found[i] == "a=1" {
Expand All @@ -102,6 +102,8 @@ func Test_initFromEnv(t *testing.T) {
nb++
} else if found[i] == "c=[1,2,3]" {
nb++
} else if found[i] == "d=e=f" {
nb++
}
}
}

0 comments on commit a95b2a9

Please sign in to comment.