Skip to content

Commit

Permalink
Merge pull request #186 from yandex/dev
Browse files Browse the repository at this point in the history
v0.5.23
  • Loading branch information
oke11o authored Apr 19, 2024
2 parents d515e10 + 44bc369 commit 74a8145
Show file tree
Hide file tree
Showing 35 changed files with 1,187 additions and 83 deletions.
1 change: 1 addition & 0 deletions .changes/v0.5.22.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## v0.5.22 - 2024-03-26
### Added
* `shared-client` for gRPC and HTTP generators
* `arm64` releases
### Changed
* Refactoring HTTP generators. Now they use common components
3 changes: 3 additions & 0 deletions .changes/v0.5.23.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## v0.5.23 - 2024-04-16
### Added
* function for generate random values in scenario
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, macOS-latest ]
arch: [ amd64 ]
arch: [ amd64, arm64 ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
Expand Down
8 changes: 8 additions & 0 deletions .mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
".changes/v0.5.20.md":"load/projects/pandora/.changes/v0.5.20.md",
".changes/v0.5.21.md":"load/projects/pandora/.changes/v0.5.21.md",
".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",
".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 Expand Up @@ -135,6 +136,9 @@
"components/providers/scenario/http/templater/templater_text_test.go":"load/projects/pandora/components/providers/scenario/http/templater/templater_text_test.go",
"components/providers/scenario/import/import.go":"load/projects/pandora/components/providers/scenario/import/import.go",
"components/providers/scenario/provider.go":"load/projects/pandora/components/providers/scenario/provider.go",
"components/providers/scenario/templater/exec.go":"load/projects/pandora/components/providers/scenario/templater/exec.go",
"components/providers/scenario/templater/func.go":"load/projects/pandora/components/providers/scenario/templater/func.go",
"components/providers/scenario/templater/func_test.go":"load/projects/pandora/components/providers/scenario/templater/func_test.go",
"components/providers/scenario/test/decode_test.go":"load/projects/pandora/components/providers/scenario/test/decode_test.go",
"components/providers/scenario/test/vs_test.go":"load/projects/pandora/components/providers/scenario/test/vs_test.go",
"components/providers/scenario/testdata/grpc_payload.hcl":"load/projects/pandora/components/providers/scenario/testdata/grpc_payload.hcl",
Expand All @@ -148,6 +152,7 @@
"components/providers/scenario/vs/vs_json.go":"load/projects/pandora/components/providers/scenario/vs/vs_json.go",
"components/providers/scenario/vs/vs_json_test.go":"load/projects/pandora/components/providers/scenario/vs/vs_json_test.go",
"components/providers/scenario/vs/vs_variables.go":"load/projects/pandora/components/providers/scenario/vs/vs_variables.go",
"components/providers/scenario/vs/vs_variables_test.go":"load/projects/pandora/components/providers/scenario/vs/vs_variables_test.go",
"core/aggregator/discard.go":"load/projects/pandora/core/aggregator/discard.go",
"core/aggregator/encoder.go":"load/projects/pandora/core/aggregator/encoder.go",
"core/aggregator/encoder_test.go":"load/projects/pandora/core/aggregator/encoder_test.go",
Expand Down Expand Up @@ -264,6 +269,7 @@
"docs/eng/providers.md":"load/projects/pandora/docs/eng/providers.md",
"docs/eng/scenario-grpc-generator.md":"load/projects/pandora/docs/eng/scenario-grpc-generator.md",
"docs/eng/scenario-http-generator.md":"load/projects/pandora/docs/eng/scenario-http-generator.md",
"docs/eng/scenario/functions.md":"load/projects/pandora/docs/eng/scenario/functions.md",
"docs/eng/scenario/variable_source.md":"load/projects/pandora/docs/eng/scenario/variable_source.md",
"docs/eng/startup.md":"load/projects/pandora/docs/eng/startup.md",
"docs/eng/tutorial.md":"load/projects/pandora/docs/eng/tutorial.md",
Expand Down Expand Up @@ -293,6 +299,7 @@
"docs/rus/providers.md":"load/projects/pandora/docs/rus/providers.md",
"docs/rus/scenario-grpc-generator.md":"load/projects/pandora/docs/rus/scenario-grpc-generator.md",
"docs/rus/scenario-http-generator.md":"load/projects/pandora/docs/rus/scenario-http-generator.md",
"docs/rus/scenario/functions.md":"load/projects/pandora/docs/rus/scenario/functions.md",
"docs/rus/scenario/variable_source.md":"load/projects/pandora/docs/rus/scenario/variable_source.md",
"docs/rus/startup.md":"load/projects/pandora/docs/rus/startup.md",
"docs/rus/tutorial.md":"load/projects/pandora/docs/rus/tutorial.md",
Expand Down Expand Up @@ -348,6 +355,7 @@
"lib/netutil/mocks/dns_cache.go":"load/projects/pandora/lib/netutil/mocks/dns_cache.go",
"lib/netutil/netutil_test.go":"load/projects/pandora/lib/netutil/netutil_test.go",
"lib/netutil/validator.go":"load/projects/pandora/lib/netutil/validator.go",
"lib/numbers/int.go":"load/projects/pandora/lib/numbers/int.go",
"lib/pointer/pointer.go":"load/projects/pandora/lib/pointer/pointer.go",
"lib/str/format.go":"load/projects/pandora/lib/str/format.go",
"lib/str/format_test.go":"load/projects/pandora/lib/str/format_test.go",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).


## v0.5.23 - 2024-04-16
### Added
* function for generate random values in scenario

## v0.5.22 - 2024-03-26
### Added
* `shared-client` for gRPC and HTTP generators
* `arm64` releases
### Changed
* Refactoring HTTP generators. Now they use common components

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.22"
const Version = "0.5.23"
const defaultConfigFile = "load"
const stdinConfigSelector = "-"

Expand Down
4 changes: 3 additions & 1 deletion components/guns/grpc/scenario/templater_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"strings"
"sync"
"text/template"

"github.com/yandex/pandora/components/providers/scenario/templater"
)

func NewTextTemplater() Templater {
Expand Down Expand Up @@ -50,7 +52,7 @@ func (t *TextTemplater) getTemplate(tmplBody, scenarioName, stepName, key string
tmpl, ok := t.templatesCache.Load(urlKey)
if !ok {
var err error
tmpl, err = template.New(urlKey).Parse(tmplBody)
tmpl, err = template.New(urlKey).Funcs(templater.GetFuncs()).Parse(tmplBody)
if err != nil {
return nil, fmt.Errorf("scenario/TextTemplater.Apply, template.New, %w", err)
}
Expand Down
12 changes: 11 additions & 1 deletion components/providers/scenario/grpc/preprocessor/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/yandex/pandora/components/guns/grpc/scenario"
"github.com/yandex/pandora/components/providers/scenario/templater"
"github.com/yandex/pandora/lib/mp"
)

Expand All @@ -26,8 +27,17 @@ func (p *PreparePreprocessor) Process(_ *scenario.Call, templateVars map[string]
return nil, errors.New("templateVars must not be nil")
}
result := make(map[string]any, len(p.Mapping))
var (
val any
err error
)
for k, v := range p.Mapping {
val, err := mp.GetMapValue(templateVars, v, p.iterator)
fun, args := templater.ParseFunc(v)
if fun != nil {
val, err = templater.ExecTemplateFuncWithVariables(fun, args, templateVars, p.iterator)
} else {
val, err = mp.GetMapValue(templateVars, v, p.iterator)
}
if err != nil {
return nil, fmt.Errorf("failed to get value for %s: %w", k, err)
}
Expand Down
31 changes: 29 additions & 2 deletions components/providers/scenario/grpc/preprocessor/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestPreprocessor_Process(t *testing.T) {
wantErr bool
}{
{
name: "Nil templateVars",
name: "nil templateVars",
prep: PreparePreprocessor{
Mapping: map[string]string{
"var1": "source.items[0].id",
Expand All @@ -25,7 +25,7 @@ func TestPreprocessor_Process(t *testing.T) {
wantErr: true,
},
{
name: "Simple Processing",
name: "simple processing",
prep: PreparePreprocessor{
Mapping: map[string]string{
"var1": "source.items[0].id",
Expand All @@ -51,6 +51,33 @@ func TestPreprocessor_Process(t *testing.T) {
},
wantErr: false,
},
{
name: "template funcs",
prep: PreparePreprocessor{
Mapping: map[string]string{
"var4": "randInt(.request.auth.min, 201)",
"var5": "randString(source.items[last].id, .request.get.letters)",
},
},
templVars: map[string]any{
"request": map[string]any{
"auth": map[string]any{"min": 200},
"get": map[string]any{"letters": "a"},
},
"source": map[string]any{
"items": []map[string]any{
{"id": "1"},
{"id": "2"},
{"id": "10"},
},
},
},
wantMap: map[string]any{
"var4": "200",
"var5": "aaaaaaaaaa",
},
wantErr: false,
},
}

for _, tt := range tests {
Expand Down
12 changes: 11 additions & 1 deletion components/providers/scenario/http/preprocessor/preprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"

"github.com/yandex/pandora/components/providers/scenario/templater"
"github.com/yandex/pandora/lib/mp"
)

Expand All @@ -20,8 +21,17 @@ func (p *Preprocessor) Process(templateVars map[string]any) (map[string]any, err
return nil, errors.New("templateVars must not be nil")
}
result := make(map[string]any, len(p.Mapping))
var (
val any
err error
)
for k, v := range p.Mapping {
val, err := mp.GetMapValue(templateVars, v, p.iterator)
fun, args := templater.ParseFunc(v)
if fun != nil {
val, err = templater.ExecTemplateFuncWithVariables(fun, args, templateVars, p.iterator)
} else {
val, err = mp.GetMapValue(templateVars, v, p.iterator)
}
if err != nil {
return nil, fmt.Errorf("failed to get value for %s: %w", k, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestPreprocessor_Process(t *testing.T) {
wantErr bool
}{
{
name: "Nil templateVars",
name: "nil templateVars",
prep: Preprocessor{
Mapping: map[string]string{
"var1": "source.items[0].id",
Expand All @@ -25,7 +25,7 @@ func TestPreprocessor_Process(t *testing.T) {
wantErr: true,
},
{
name: "Simple Processing",
name: "simple processing",
prep: Preprocessor{
Mapping: map[string]string{
"var1": "source.items[0].id",
Expand All @@ -51,6 +51,33 @@ func TestPreprocessor_Process(t *testing.T) {
},
wantErr: false,
},
{
name: "template funcs",
prep: Preprocessor{
Mapping: map[string]string{
"var4": "randInt(.request.auth.min, 201)",
"var5": "randString(source.items[last].id, .request.get.letters)",
},
},
templVars: map[string]any{
"request": map[string]any{
"auth": map[string]any{"min": 200},
"get": map[string]any{"letters": "a"},
},
"source": map[string]any{
"items": []map[string]any{
{"id": "1"},
{"id": "2"},
{"id": "10"},
},
},
},
wantMap: map[string]any{
"var4": "200",
"var5": "aaaaaaaaaa",
},
wantErr: false,
},
}

for _, tt := range tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"

gun "github.com/yandex/pandora/components/guns/http_scenario"
"github.com/yandex/pandora/components/providers/scenario/templater"
)

func NewHTMLTemplater() Templater {
Expand Down Expand Up @@ -64,7 +65,7 @@ func (t *HTMLTemplater) getTemplate(tmplBody, scenarioName, stepName, key string
tmpl, ok := t.templatesCache.Load(urlKey)
if !ok {
var err error
tmpl, err = template.New(urlKey).Parse(tmplBody)
tmpl, err = template.New(urlKey).Funcs(templater.GetFuncs()).Parse(tmplBody)
if err != nil {
return nil, fmt.Errorf("scenario/TextTemplater.Apply, template.New, %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"text/template"

gun "github.com/yandex/pandora/components/guns/http_scenario"
"github.com/yandex/pandora/components/providers/scenario/templater"
)

func NewTextTemplater() Templater {
Expand Down Expand Up @@ -64,7 +65,7 @@ func (t *TextTemplater) getTemplate(tmplBody, scenarioName, stepName, key string
tmpl, ok := t.templatesCache.Load(urlKey)
if !ok {
var err error
tmpl, err = template.New(urlKey).Parse(tmplBody)
tmpl, err = template.New(urlKey).Funcs(templater.GetFuncs()).Parse(tmplBody)
if err != nil {
return nil, fmt.Errorf("scenario/TextTemplater.Apply, template.New, %w", err)
}
Expand Down
Loading

0 comments on commit 74a8145

Please sign in to comment.