Skip to content

Commit

Permalink
fix: ts vars interpolation only once (#379)
Browse files Browse the repository at this point in the history
* fix: ts vars interpolation only once

close #377

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Mar 5, 2021
1 parent 33fe791 commit 02751cc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion process_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ func (v *Venom) readFiles(ctx context.Context, filesPath []string) (err error) {
// we take default vars from the testsuite, only if it's not already is global vars
for k, value := range varsFromPartial {
if _, ok := varCloned[k]; !ok || (varCloned[k] == "{}" && varCloned["__Len__"] == "0") {
varCloned[k] = value
// we interpolate the value of vars here, to do it only once per ts
valueInterpolated, err := interpolate.Do(value, varsFromPartial)
if err != nil {
return errors.Wrapf(err, "unable to parse variable %q", k)
}
varCloned[k] = valueInterpolated
}
}

Expand Down
20 changes: 20 additions & 0 deletions tests/random_vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: testsuite
vars:
phone_number: "+3375{{ randNumeric 7 }}"
testcases:
- name: test 1
steps:
- type: exec
script: echo '{{.phone_number}}'
info: '{{.phone_number}} test 1'
vars:
myvariable:
from: result.systemout
regex: ([a-z0-9\+]+)
- name: test 2
steps:
- type: exec
script: echo '{{.phone_number}}'
info: '{{.phone_number}} test 2'
assertions:
- result.systemout ShouldEqual {{.test-1.myvariable}}

0 comments on commit 02751cc

Please sign in to comment.