Skip to content

Commit

Permalink
fix bug with randInt() function without args
Browse files Browse the repository at this point in the history
651d88400baff997505355147c6aab0682aa8ecb
  • Loading branch information
oke11o committed May 16, 2024
1 parent a926b55 commit 6a7b878
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changes/v0.5.25.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## v0.5.25 - 2024-05-16
### Fixed
* randInt function without args in preprocessor
1 change: 1 addition & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
".changes/v0.5.22.md":"load/projects/pandora/.changes/v0.5.22.md",
".changes/v0.5.23.md":"load/projects/pandora/.changes/v0.5.23.md",
".changes/v0.5.24.md":"load/projects/pandora/.changes/v0.5.24.md",
".changes/v0.5.25.md":"load/projects/pandora/.changes/v0.5.25.md",
".changie.yaml":"load/projects/pandora/.changie.yaml",
".github/workflows/release.yml":"load/projects/pandora/.github/workflows/release.yml",
".github/workflows/test.yml":"load/projects/pandora/.github/workflows/test.yml",
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).


## v0.5.25 - 2024-05-16
### Fixed
* randInt function without args in preprocessor

## v0.5.24 - 2024-04-27
### Added
* HCL scenario: add support for "locals" block in hcl
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"go.uber.org/zap/zapcore"
)

const Version = "0.5.24"
const Version = "0.5.25"
const defaultConfigFile = "load"
const stdinConfigSelector = "-"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ func TestTextTemplater_Apply_WithRandFunct(t *testing.T) {
},
expectError: false,
},
{
name: "randInt with no args",
parts: &gun.RequestParts{Body: []byte(`{{ randInt }}`)},
vs: map[string]interface{}{},
assertBody: func(t *testing.T, body string) {
v, err := strconv.ParseInt(body, 10, 64)
require.NoError(t, err)
require.InDelta(t, 5, v, 5)
},
expectError: false,
},
{
name: "randInt with literals",
parts: &gun.RequestParts{Body: []byte(`{{ randInt -10 }}`)},
Expand Down
3 changes: 3 additions & 0 deletions components/providers/scenario/templater/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func parseStr(v string) (string, []string) {
}
v = strings.TrimSuffix(strings.Join(args[1:], "("), ")")
args = strings.Split(v, ",")
if len(args) == 1 && args[0] == "" {
return name, nil
}
for i := 0; i < len(args); i++ {
args[i] = strings.TrimSpace(args[i])
}
Expand Down
14 changes: 13 additions & 1 deletion components/providers/scenario/templater/func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,23 @@ func TestParseFunc(t *testing.T) {
wantArgs []string
}{
{
name: "Simple",
name: "Two args",
arg: "randInt(10, 20)",
wantF: RandInt,
wantArgs: []string{"10", "20"},
},
{
name: "One arg",
arg: "randInt(10)",
wantF: RandInt,
wantArgs: []string{"10"},
},
{
name: "No args",
arg: "randInt()",
wantF: RandInt,
wantArgs: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 6a7b878

Please sign in to comment.