Skip to content

Commit 6a7b878

Browse files
committed
fix bug with randInt() function without args
651d88400baff997505355147c6aab0682aa8ecb
1 parent a926b55 commit 6a7b878

7 files changed

Lines changed: 36 additions & 2 deletions

File tree

.changes/v0.5.25.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## v0.5.25 - 2024-05-16
2+
### Fixed
3+
* randInt function without args in preprocessor

.mapping.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
".changes/v0.5.22.md":"load/projects/pandora/.changes/v0.5.22.md",
2323
".changes/v0.5.23.md":"load/projects/pandora/.changes/v0.5.23.md",
2424
".changes/v0.5.24.md":"load/projects/pandora/.changes/v0.5.24.md",
25+
".changes/v0.5.25.md":"load/projects/pandora/.changes/v0.5.25.md",
2526
".changie.yaml":"load/projects/pandora/.changie.yaml",
2627
".github/workflows/release.yml":"load/projects/pandora/.github/workflows/release.yml",
2728
".github/workflows/test.yml":"load/projects/pandora/.github/workflows/test.yml",

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
66
and is generated by [Changie](https://github.com/miniscruff/changie).
77

88

9+
## v0.5.25 - 2024-05-16
10+
### Fixed
11+
* randInt function without args in preprocessor
12+
913
## v0.5.24 - 2024-04-27
1014
### Added
1115
* HCL scenario: add support for "locals" block in hcl

cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"go.uber.org/zap/zapcore"
2626
)
2727

28-
const Version = "0.5.24"
28+
const Version = "0.5.25"
2929
const defaultConfigFile = "load"
3030
const stdinConfigSelector = "-"
3131

components/providers/scenario/http/templater/templater_text_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ func TestTextTemplater_Apply_WithRandFunct(t *testing.T) {
237237
},
238238
expectError: false,
239239
},
240+
{
241+
name: "randInt with no args",
242+
parts: &gun.RequestParts{Body: []byte(`{{ randInt }}`)},
243+
vs: map[string]interface{}{},
244+
assertBody: func(t *testing.T, body string) {
245+
v, err := strconv.ParseInt(body, 10, 64)
246+
require.NoError(t, err)
247+
require.InDelta(t, 5, v, 5)
248+
},
249+
expectError: false,
250+
},
240251
{
241252
name: "randInt with literals",
242253
parts: &gun.RequestParts{Body: []byte(`{{ randInt -10 }}`)},

components/providers/scenario/templater/func.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ func parseStr(v string) (string, []string) {
4646
}
4747
v = strings.TrimSuffix(strings.Join(args[1:], "("), ")")
4848
args = strings.Split(v, ",")
49+
if len(args) == 1 && args[0] == "" {
50+
return name, nil
51+
}
4952
for i := 0; i < len(args); i++ {
5053
args[i] = strings.TrimSpace(args[i])
5154
}

components/providers/scenario/templater/func_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,23 @@ func TestParseFunc(t *testing.T) {
191191
wantArgs []string
192192
}{
193193
{
194-
name: "Simple",
194+
name: "Two args",
195195
arg: "randInt(10, 20)",
196196
wantF: RandInt,
197197
wantArgs: []string{"10", "20"},
198198
},
199+
{
200+
name: "One arg",
201+
arg: "randInt(10)",
202+
wantF: RandInt,
203+
wantArgs: []string{"10"},
204+
},
205+
{
206+
name: "No args",
207+
arg: "randInt()",
208+
wantF: RandInt,
209+
wantArgs: nil,
210+
},
199211
}
200212
for _, tt := range tests {
201213
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)