/
testing.go
30 lines (26 loc) Β· 689 Bytes
/
testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package codegen
import (
"bytes"
"testing"
"goa.design/goa/codegen"
"goa.design/goa/codegen/service"
"goa.design/goa/expr"
)
// RunGRPCDSL returns the GRPC DSL root resulting from running the given DSL.
// It is used only in tests.
func RunGRPCDSL(t *testing.T, dsl func()) *expr.RootExpr {
// reset all roots and codegen data structures
service.Services = make(service.ServicesData)
GRPCServices = make(ServicesData)
return expr.RunDSL(t, dsl)
}
func sectionCode(t *testing.T, section ...*codegen.SectionTemplate) string {
t.Helper()
var code bytes.Buffer
for _, s := range section {
if err := s.Write(&code); err != nil {
t.Fatal(err)
}
}
return code.String()
}