diff --git a/.changes/v0.5.25.md b/.changes/v0.5.25.md new file mode 100644 index 000000000..a01ec38f9 --- /dev/null +++ b/.changes/v0.5.25.md @@ -0,0 +1,3 @@ +## v0.5.25 - 2024-05-16 +### Fixed +* randInt function without args in preprocessor diff --git a/.mapping.json b/.mapping.json index e903f7fbc..da0684284 100644 --- a/.mapping.json +++ b/.mapping.json @@ -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", diff --git a/CHANGELOG.md b/CHANGELOG.md index a5ab3d30f..cfbfb0e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cli/cli.go b/cli/cli.go index 1171f0163..4b9c6979b 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -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 = "-" diff --git a/components/providers/scenario/http/templater/templater_text_test.go b/components/providers/scenario/http/templater/templater_text_test.go index d997d0724..87aba27a3 100644 --- a/components/providers/scenario/http/templater/templater_text_test.go +++ b/components/providers/scenario/http/templater/templater_text_test.go @@ -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 }}`)}, diff --git a/components/providers/scenario/templater/func.go b/components/providers/scenario/templater/func.go index 4437cb9a0..2f3517be6 100644 --- a/components/providers/scenario/templater/func.go +++ b/components/providers/scenario/templater/func.go @@ -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]) } diff --git a/components/providers/scenario/templater/func_test.go b/components/providers/scenario/templater/func_test.go index 8b29a819f..036272b22 100644 --- a/components/providers/scenario/templater/func_test.go +++ b/components/providers/scenario/templater/func_test.go @@ -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) {