Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions testing/codegen/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func TestGenerateClient(t *testing.T) {
"with-result": {
DSL: testdata.WithResultDSL,
Code: map[string][]string{
"client-methods": {testdata.WithResultCode},
"client-methods": {testdata.ClientMethodsWithResultCode},
},
Path: "gen/with_result_service/with_result_servicetest/client.go",
},
"without-result": {
DSL: testdata.WithoutResultDSL,
Code: map[string][]string{
"client-methods": {testdata.WithoutResultCode},
"client-methods": {testdata.ClientMethodsWithoutResultCode},
},
Path: "gen/without_result_service/without_result_servicetest/client.go",
},
Expand Down
47 changes: 47 additions & 0 deletions testing/codegen/scenarios_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package codegen

import (
"testing"

"github.com/stretchr/testify/assert"
"goa.design/goa/v3/codegen/service"
httpcodegen "goa.design/goa/v3/http/codegen"
"goa.design/plugins/v3/testing/codegen/testdata"
)

func TestGenerateScenarios(t *testing.T) {
cases := map[string]struct {
DSL func()
Code map[string][]string
Path string
}{
"with-result": {
DSL: testdata.WithResultDSL,
Code: map[string][]string{
"scenario-runner": {testdata.ScenarioRunnerWithResultCode},
},
Path: "gen/with_result_service/with_result_servicetest/scenarios.go",
},
"without-result": {
DSL: testdata.WithoutResultDSL,
Code: map[string][]string{
"scenario-runner": {testdata.ScenarioRunnerWithoutResultCode},
},
Path: "gen/without_result_service/without_result_servicetest/scenarios.go",
},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
root := httpcodegen.RunHTTPDSL(t, c.DSL)
services := service.NewServicesData(root)
svc := root.Services[0]
svcData := services.Get(svc.Name)
fs := generateScenarios("", svcData, root, svc)
f := fs[0]
assert.Equal(t, c.Path, f.Path)
for sec, secCode := range c.Code {
testCode(t, f, sec, secCode)
}
})
}
}
6 changes: 2 additions & 4 deletions testing/codegen/templates/scenario_runner.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,8 @@ func (r *ScenarioRunner) executeMethod(ctx context.Context, client *Client, meth
if err := r.mapToStruct(payload, p); err != nil {
return nil, fmt.Errorf("invalid payload for {{ .Name }}: %w", err)
}
return client.{{ .VarName }}(ctx, p)
{{- else }}
return client.{{ .VarName }}(ctx)
{{- end }}
return {{ if not .ResultRef }}nil, {{ end }}client.{{ .VarName }}(ctx{{ if .PayloadRef }}, p{{ end }})
{{- end }}
default:
return nil, fmt.Errorf("unknown method: %s", method)
Expand Down Expand Up @@ -329,4 +327,4 @@ func (r *ScenarioRunner) selectTransport(client *Client, transport string) *Clie
default:
return client // auto or unknown - use default
}
}
}
Loading
Loading