Skip to content

Commit 5c75d4c

Browse files
authored
Use non-global root expressions for each test (#198)
1 parent 7a69dc1 commit 5c75d4c

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

cors/generate_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"goa.design/goa/v3/codegen"
1010
"goa.design/goa/v3/codegen/service"
1111
"goa.design/goa/v3/eval"
12-
"goa.design/goa/v3/expr"
1312
httpcodegen "goa.design/goa/v3/http/codegen"
1413

1514
"goa.design/plugins/v3/cors"
@@ -43,11 +42,11 @@ func NewCORSHandler() http.Handler {
4342
}
4443
for _, c := range cases {
4544
t.Run(c.Name, func(t *testing.T) {
46-
httpcodegen.RunHTTPDSL(t, c.DSL)
47-
services := httpcodegen.NewServicesData(service.NewServicesData(expr.Root), expr.Root.API.HTTP)
45+
root := httpcodegen.RunHTTPDSL(t, c.DSL)
46+
services := httpcodegen.NewServicesData(service.NewServicesData(root), root.API.HTTP)
4847
fs := httpcodegen.ServerFiles("", services)
4948
require.Len(t, fs, c.CodeGenCount)
50-
cors.Generate("", []eval.Root{expr.Root}, fs)
49+
cors.Generate("", []eval.Root{root}, fs)
5150
expectedCodeIndex := -1
5251
for _, f := range fs {
5352
if filepath.Base(f.Path) != "server.go" {

goakit/encode_decode_files_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/stretchr/testify/assert"
88
"github.com/stretchr/testify/require"
99
"goa.design/goa/v3/codegen"
10-
"goa.design/goa/v3/expr"
1110
httpcodegen "goa.design/goa/v3/http/codegen"
1211

1312
"goa.design/plugins/v3/goakit/testdata"
@@ -67,8 +66,8 @@ func TestServerEncodeDecode(t *testing.T) {
6766
}
6867
for name, c := range cases {
6968
t.Run(name, func(t *testing.T) {
70-
httpcodegen.RunHTTPDSL(t, c.DSL)
71-
fs := EncodeDecodeFiles("", expr.Root)
69+
root := httpcodegen.RunHTTPDSL(t, c.DSL)
70+
fs := EncodeDecodeFiles("", root)
7271
require.Len(t, fs, 2)
7372
var found bool
7473
for _, f := range fs {
@@ -126,8 +125,8 @@ func TestClientEncodeDecode(t *testing.T) {
126125
}
127126
for name, c := range cases {
128127
t.Run(name, func(t *testing.T) {
129-
httpcodegen.RunHTTPDSL(t, c.DSL)
130-
fs := EncodeDecodeFiles("", expr.Root)
128+
root := httpcodegen.RunHTTPDSL(t, c.DSL)
129+
fs := EncodeDecodeFiles("", root)
131130
require.Len(t, fs, 2)
132131
var found bool
133132
for _, f := range fs {

goakit/generate_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"goa.design/goa/v3/codegen"
1111
"goa.design/goa/v3/codegen/generator"
1212
"goa.design/goa/v3/eval"
13-
"goa.design/goa/v3/expr"
1413
httpcodegen "goa.design/goa/v3/http/codegen"
1514
"goa.design/plugins/v3/goakit/testdata"
1615
)
@@ -25,8 +24,8 @@ func TestGenerate(t *testing.T) {
2524
}
2625
for name, c := range cases {
2726
t.Run(name, func(t *testing.T) {
28-
httpcodegen.RunHTTPDSL(t, c.DSL)
29-
roots := []eval.Root{expr.Root}
27+
root := httpcodegen.RunHTTPDSL(t, c.DSL)
28+
roots := []eval.Root{root}
3029
files := generateFiles(t, roots)
3130
newFiles, err := Generate("", roots, files)
3231
if err != nil {
@@ -49,8 +48,8 @@ func TestGoakitify(t *testing.T) {
4948
}
5049
for name, dsl := range cases {
5150
t.Run(name, func(t *testing.T) {
52-
httpcodegen.RunHTTPDSL(t, dsl)
53-
roots := []eval.Root{expr.Root}
51+
root := httpcodegen.RunHTTPDSL(t, dsl)
52+
roots := []eval.Root{root}
5453
files := generateFiles(t, roots)
5554
newFiles, err := Goakitify("", roots, files)
5655
require.NoError(t, err)
@@ -111,8 +110,8 @@ func TestGoakitifyExample(t *testing.T) {
111110
}
112111
for name, c := range cases {
113112
t.Run(name, func(t *testing.T) {
114-
httpcodegen.RunHTTPDSL(t, c.DSL)
115-
roots := []eval.Root{expr.Root}
113+
root := httpcodegen.RunHTTPDSL(t, c.DSL)
114+
roots := []eval.Root{root}
116115
files := generateExamples(t, roots)
117116
files, err := GoakitifyExample("", roots, files)
118117
require.NoError(t, err)

goakit/mount_files_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package goakit
33
import (
44
"testing"
55

6-
"goa.design/goa/v3/expr"
76
httpcodegen "goa.design/goa/v3/http/codegen"
87
"goa.design/plugins/v3/goakit/testdata"
98
)
@@ -49,8 +48,8 @@ func TestMountFiles(t *testing.T) {
4948
}
5049
for name, c := range cases {
5150
t.Run(name, func(t *testing.T) {
52-
httpcodegen.RunHTTPDSL(t, c.DSL)
53-
fs := MountFiles(expr.Root)
51+
root := httpcodegen.RunHTTPDSL(t, c.DSL)
52+
fs := MountFiles(root)
5453
if len(fs) != 1 {
5554
t.Fatalf("got %d files, expected 1", len(fs))
5655
}

i18n/generate_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func TestPrepare(t *testing.T) {
2626
for _, c := range cases {
2727
t.Run(c.Name, func(t *testing.T) {
2828
os.Setenv("GOA_I18N", c.Locales)
29-
httpcodegen.RunHTTPDSL(t, c.DSL)
29+
root := httpcodegen.RunHTTPDSL(t, c.DSL)
3030

31-
roots, _ := eval.Context.Roots()
31+
roots := []eval.Root{root}
3232

3333
// Expect Description to be empty
3434
checkExpr(roots, &expr.ServiceExpr{}, func(se interface{}) {
@@ -63,11 +63,11 @@ func checkExpr(roots []eval.Root, t interface{}, cb func(se interface{})) {
6363
func TestGenerate(t *testing.T) {
6464
os.Setenv("GOA_I18N", "en,nl")
6565

66-
httpcodegen.RunHTTPDSL(t, testdata.SimpleI18nDSL)
67-
roots, _ := eval.Context.Roots()
66+
root := httpcodegen.RunHTTPDSL(t, testdata.SimpleI18nDSL)
67+
roots := []eval.Root{root}
6868
i18n.Prepare("", roots)
6969

70-
fs, _ := httpcodegen.OpenAPIFiles(expr.Root)
70+
fs, _ := httpcodegen.OpenAPIFiles(root)
7171
gfs, _ := i18n.Generate("", roots, fs)
7272

7373
if len(gfs) != 8 {

0 commit comments

Comments
 (0)