Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: interpolate arg var only once #563

Merged
merged 3 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/venom/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ include ../../.build/go.mk
build: $(CROSS_COMPILED_BINARIES) ## Run build

clean:
@rm -f *.dump.json *_profile.prof test_results.xml venom.log
@rm -f *.dump.json *_profile.prof *.xml *.log *.pprof *.json
@rm -f venom
@rm -rf dist
@rm -rf dist
16 changes: 14 additions & 2 deletions cmd/venom/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/ovh/cds/sdk/interpolate"
"github.com/ovh/venom"
"github.com/ovh/venom/executors/amqp"
"github.com/ovh/venom/executors/dbfixtures"
Expand Down Expand Up @@ -435,9 +436,16 @@ func readInitialVariables(ctx context.Context, argsVars []string, argVarsFiles [
if err != nil {
return nil, err
}
if err := yaml.Unmarshal(btes, &tmpResult); err != nil {

stemp, err := interpolate.Do(string(btes), nil)
if err != nil {
return nil, fmt.Errorf("unable to interpolate file %v", err)
}

if err := yaml.Unmarshal([]byte(stemp), &tmpResult); err != nil {
return nil, err
}

for k, v := range tmpResult {
result[k] = v
venom.Debug(ctx, "Adding variable from vars-files %s=%s", k, v)
Expand All @@ -452,7 +460,11 @@ func readInitialVariables(ctx context.Context, argsVars []string, argVarsFiles [
if len(tuple) < 2 {
return nil, fmt.Errorf("invalid variable declaration: %v", arg)
}
result[tuple[0]] = cast(tuple[1])
stemp, err := interpolate.Do(tuple[1], nil)
if err != nil {
return nil, fmt.Errorf("unable to interpolate arg %s: %v", arg, err)
}
result[tuple[0]] = cast(stemp)
venom.Debug(ctx, "Adding variable from vars arg %s=%s", tuple[0], result[tuple[0]])
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ clean:

merge-coverage:
@docker run -v `pwd`:/workspace golang:1.17 sh -c "\
go get -u github.com/wadey/gocovmerge && \
go install github.com/wadey/gocovmerge@latest && \
cd /workspace && \
gocovmerge $(COVER_FILES) > /workspace/venom.cover.out \
"
17 changes: 17 additions & 0 deletions tests/interpolate_once.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: e
version: 2
testcases:
- name: myvar_first
steps:
- type: exec
script: "echo myvar {{.randomvar}}"
info: "{{.result.systemout}}"

- name: myvar_second
steps:
- type: exec
script: "echo myvar {{.randomvar}}"
info: "{{.result.systemout}}"
assertions:
- result.systemout ShouldContainSubstring "{{.myvar_first.result.systemout}}"
3 changes: 2 additions & 1 deletion tests/vars/vars.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
myvar: "{{.MY_ENVAR}}"
myvar: "{{.MY_ENVAR}}"
randomvar: '{{ randAlpha 3 }}'