Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 11 additions & 4 deletions testing/codegen/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,26 @@ func TestGenerateClient(t *testing.T) {
Code map[string][]string
Path string
}{
"with-payload": {
DSL: testdata.WithPayloadDSL,
Code: map[string][]string{
"client-methods": {testdata.ClientMethodsWithPayloadCode},
},
Path: "gen/with_payload_service/with_payload_servicetest/client.go",
},
"with-result": {
DSL: testdata.WithResultDSL,
Code: map[string][]string{
"client-methods": {testdata.ClientMethodsWithResultCode},
},
Path: "gen/with_result_service/with_result_servicetest/client.go",
},
"without-result": {
DSL: testdata.WithoutResultDSL,
"without-payload-result": {
DSL: testdata.WithoutPayloadResultDSL,
Code: map[string][]string{
"client-methods": {testdata.ClientMethodsWithoutResultCode},
"client-methods": {testdata.ClientMethodsWithoutPayloadResultCode},
},
Path: "gen/without_result_service/without_result_servicetest/client.go",
Path: "gen/without_payload_result_service/without_payload_result_servicetest/client.go",
},
}
for name, c := range cases {
Expand Down
10 changes: 10 additions & 0 deletions testing/codegen/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,13 @@ func hasMethodJSONRPC(root *expr.RootExpr, svc *expr.ServiceExpr, m *expr.Method
}
return false
}

// hasStreams checks if the service has streaming methods.
func hasPayloads(svc *expr.ServiceExpr) bool {
for _, m := range svc.Methods {
if m.Payload.Type != expr.Empty || m.StreamingPayload.Type != expr.Empty {
return true
}
}
return false
}
15 changes: 11 additions & 4 deletions testing/codegen/scenarios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,26 @@ func TestGenerateScenarios(t *testing.T) {
Code map[string][]string
Path string
}{
"with-payload": {
DSL: testdata.WithPayloadDSL,
Code: map[string][]string{
"scenario-runner": {testdata.ScenarioRunnerWithPayloadCode},
},
Path: "gen/with_payload_service/with_payload_servicetest/scenarios.go",
},
"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,
"without-payload-result": {
DSL: testdata.WithoutPayloadResultDSL,
Code: map[string][]string{
"scenario-runner": {testdata.ScenarioRunnerWithoutResultCode},
"scenario-runner": {testdata.ScenarioRunnerWithoutPayloadResultCode},
},
Path: "gen/without_result_service/without_result_servicetest/scenarios.go",
Path: "gen/without_payload_result_service/without_payload_result_servicetest/scenarios.go",
},
}
for name, c := range cases {
Expand Down
52 changes: 27 additions & 25 deletions testing/codegen/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ import (
type (
// suiteData contains data for generating test suite.
suiteData struct {
Package string
Service *service.Data
ImportPath string
TestPkg string // Package alias for the test harness
NonStream []*suiteMethodData
Stream []*suiteMethodData
HasErrors bool
HasStreams bool
HasHTTP bool
HasGRPC bool
HasJSONRPC bool
UseTD bool
UseCtx bool
Package string
Service *service.Data
ImportPath string
TestPkg string // Package alias for the test harness
NonStream []*suiteMethodData
Stream []*suiteMethodData
HasErrors bool
HasStreams bool
HasHTTP bool
HasGRPC bool
HasJSONRPC bool
HasPayloads bool
UseTD bool
UseCtx bool
}

// suiteTarget describes one transport/mode target to exercise for a method.
Expand Down Expand Up @@ -64,7 +65,7 @@ func generateSuiteTopLevel(genpkg string, examplePkg string, root *expr.RootExpr
{Path: "testing"},
{Path: "time"},
{Path: filepath.Join(genpkg, data.Service.PathName), Name: data.Service.PkgName},
{Path: filepath.Join(genpkg, data.Service.PathName, data.Service.PathName+"test"), Name: data.Service.VarName+"test"},
{Path: filepath.Join(genpkg, data.Service.PathName, data.Service.PathName+"test"), Name: data.Service.VarName + "test"},
}
sections := []*codegen.SectionTemplate{
// Use empty title to generate header without "DO NOT EDIT" comment, like Goa examples
Expand All @@ -89,17 +90,18 @@ func generateSuiteTopLevel(genpkg string, examplePkg string, root *expr.RootExpr
func buildSuiteData(genpkg, pkg string, root *expr.RootExpr, svc *expr.ServiceExpr) *suiteData {
sd := service.NewServicesData(root).Get(svc.Name)
data := &suiteData{
Package: pkg,
Service: sd,
ImportPath: filepath.Join(genpkg, sd.PathName),
TestPkg: sd.VarName + "test",
NonStream: make([]*suiteMethodData, 0, len(svc.Methods)),
Stream: make([]*suiteMethodData, 0, len(svc.Methods)),
HasErrors: hasErrors(svc),
HasStreams: hasStreams(svc),
HasHTTP: hasHTTPTransport(root, svc),
HasGRPC: hasGRPCTransport(root, svc),
HasJSONRPC: hasJSONRPCTransport(root, svc),
Package: pkg,
Service: sd,
ImportPath: filepath.Join(genpkg, sd.PathName),
TestPkg: sd.VarName + "test",
NonStream: make([]*suiteMethodData, 0, len(svc.Methods)),
Stream: make([]*suiteMethodData, 0, len(svc.Methods)),
HasErrors: hasErrors(svc),
HasStreams: hasStreams(svc),
HasHTTP: hasHTTPTransport(root, svc),
HasGRPC: hasGRPCTransport(root, svc),
HasJSONRPC: hasJSONRPCTransport(root, svc),
HasPayloads: hasPayloads(svc),
}
for _, m := range svc.Methods {
md := &suiteMethodData{Method: sd.Method(m.Name)}
Expand Down
15 changes: 11 additions & 4 deletions testing/codegen/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@ func TestGenerateSuiteTopLevel(t *testing.T) {
Code map[string][]string
Path string
}{
"with-payload": {
DSL: testdata.WithPayloadDSL,
Code: map[string][]string{
"suite-test": {testdata.SuiteTestWithPayloadCode},
},
Path: "with_payload_service_suite_test.go",
},
"with-result": {
DSL: testdata.WithResultDSL,
Code: map[string][]string{
"suite-test": {testdata.SuiteTestWithResultCode},
},
Path: "with_result_service_suite_test.go",
},
"without-result": {
DSL: testdata.WithoutResultDSL,
"without-payload-result": {
DSL: testdata.WithoutPayloadResultDSL,
Code: map[string][]string{
"suite-test": {testdata.SuiteTestWithoutResultCode},
"suite-test": {testdata.SuiteTestWithoutPayloadResultCode},
},
Path: "without_result_service_suite_test.go",
Path: "without_payload_result_service_suite_test.go",
},
}
for name, c := range cases {
Expand Down
2 changes: 2 additions & 0 deletions testing/codegen/templates/suite_test.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ func Run{{ .Service.StructName }}Harness(t *testing.T, svc {{ .Service.PkgName }
h := {{ .TestPkg }}.NewHarness(t, svc)
defer h.Close()

{{ if .HasPayloads }}
td := {{ .TestPkg }}.NewTestData()
{{- end }}

{{- range .NonStream }}
{{- $m := . }}
Expand Down
Loading
Loading