Skip to content

Commit eb8d97f

Browse files
authored
test(endtoend): Enable for more build targets (#3041)
Now that PostgreSQL support works on Windows, make sure that the end-to-end tests pass. Skip a few individual tests on Windows or environments where wasmtime is disabled.
1 parent ecb0491 commit eb8d97f

File tree

8 files changed

+71
-10
lines changed

8 files changed

+71
-10
lines changed

internal/endtoend/case_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type Exec struct {
2121
Command string `json:"command"`
2222
Contexts []string `json:"contexts"`
2323
Process string `json:"process"`
24+
OS []string `json:"os"`
25+
WASM bool `json:"wasm"`
2426
Env map[string]string `json:"env"`
2527
}
2628

internal/endtoend/ddl_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"runtime"
89
"slices"
910
"strings"
1011
"testing"
@@ -19,6 +20,10 @@ import (
1920
)
2021

2122
func TestValidSchema(t *testing.T) {
23+
if os.Getenv("CI") != "" && runtime.GOOS != "linux" {
24+
t.Skipf("only run these tests in CI on linux: %s %s", os.Getenv("CI"), runtime.GOOS)
25+
}
26+
2227
ctx := context.Background()
2328

2429
projectID := os.Getenv("CI_SQLC_PROJECT_ID")

internal/endtoend/endtoend_test.go

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// Currently requires cgo for wasmtime and has line-ending issues on windows.
2-
//go:build cgo && !windows
3-
// +build cgo,!windows
4-
51
package main
62

73
import (
@@ -10,6 +6,7 @@ import (
106
"os"
117
osexec "os/exec"
128
"path/filepath"
9+
"runtime"
1310
"slices"
1411
"strings"
1512
"testing"
@@ -19,9 +16,24 @@ import (
1916

2017
"github.com/sqlc-dev/sqlc/internal/cmd"
2118
"github.com/sqlc-dev/sqlc/internal/config"
19+
"github.com/sqlc-dev/sqlc/internal/ext/wasm"
2220
"github.com/sqlc-dev/sqlc/internal/opts"
2321
)
2422

23+
func lineEndings() cmp.Option {
24+
return cmp.Transformer("LineEndings", func(in string) string {
25+
// Replace Windows new lines with Unix newlines
26+
return strings.Replace(in, "\r\n", "\n", -1)
27+
})
28+
}
29+
30+
func stderrTransformer() cmp.Option {
31+
return cmp.Transformer("Stderr", func(in string) string {
32+
s := strings.Replace(in, "\r", "", -1)
33+
return strings.Replace(s, "\\", "/", -1)
34+
})
35+
}
36+
2537
func TestExamples(t *testing.T) {
2638
t.Parallel()
2739
ctx := context.Background()
@@ -115,7 +127,15 @@ func TestReplay(t *testing.T) {
115127
}
116128
},
117129
Enabled: func() bool {
118-
return len(os.Getenv("SQLC_AUTH_TOKEN")) > 0
130+
// Return false if no auth token exists
131+
if len(os.Getenv("SQLC_AUTH_TOKEN")) == 0 {
132+
return false
133+
}
134+
// In CI, only run these tests from Linux
135+
if os.Getenv("CI") != "" {
136+
return runtime.GOOS == "linux"
137+
}
138+
return true
119139
},
120140
},
121141
}
@@ -157,6 +177,16 @@ func TestReplay(t *testing.T) {
157177
}
158178
}
159179

180+
if args.WASM && !wasm.Enabled() {
181+
t.Skipf("wasm support not enabled")
182+
}
183+
184+
if len(args.OS) > 0 {
185+
if !slices.Contains(args.OS, runtime.GOOS) {
186+
t.Skipf("unsupported os: %s", runtime.GOOS)
187+
}
188+
}
189+
160190
opts := cmd.Options{
161191
Env: cmd.Env{
162192
Debug: opts.DebugFromString(args.Env["SQLCDEBUG"]),
@@ -184,7 +214,11 @@ func TestReplay(t *testing.T) {
184214
t.Fatalf("sqlc %s failed: %s", args.Command, stderr.String())
185215
}
186216

187-
diff := cmp.Diff(strings.TrimSpace(expected), strings.TrimSpace(stderr.String()))
217+
diff := cmp.Diff(
218+
strings.TrimSpace(expected),
219+
strings.TrimSpace(stderr.String()),
220+
stderrTransformer(),
221+
)
188222
if diff != "" {
189223
t.Fatalf("stderr differed (-want +got):\n%s", diff)
190224
}
@@ -237,15 +271,20 @@ func cmpDirectory(t *testing.T, dir string, actual map[string]string) {
237271
t.Fatal(err)
238272
}
239273

240-
if !cmp.Equal(expected, actual, cmpopts.EquateEmpty()) {
274+
opts := []cmp.Option{
275+
cmpopts.EquateEmpty(),
276+
lineEndings(),
277+
}
278+
279+
if !cmp.Equal(expected, actual, opts...) {
241280
t.Errorf("%s contents differ", dir)
242281
for name, contents := range expected {
243282
name := name
244283
if actual[name] == "" {
245284
t.Errorf("%s is empty", name)
246285
return
247286
}
248-
if diff := cmp.Diff(contents, actual[name]); diff != "" {
287+
if diff := cmp.Diff(contents, actual[name], opts...); diff != "" {
249288
t.Errorf("%s differed (-want +got):\n%s", name, diff)
250289
}
251290
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"process": "sqlc-gen-test"
3-
}
2+
"process": "sqlc-gen-test",
3+
"os": ["linux", "darwin"]
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"wasm": true
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"wasm": true
3+
}

internal/ext/wasm/nowasm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010
"google.golang.org/grpc/status"
1111
)
1212

13+
func Enabled() bool {
14+
return false
15+
}
16+
1317
func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error {
1418
return status.Error(codes.FailedPrecondition, "sqlc built without wasmtime support")
1519
}

internal/ext/wasm/wasm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import (
3131
"github.com/sqlc-dev/sqlc/internal/plugin"
3232
)
3333

34+
func Enabled() bool {
35+
return true
36+
}
37+
3438
// This version must be updated whenever the wasmtime-go dependency is updated
3539
const wasmtimeVersion = `v14.0.0`
3640

0 commit comments

Comments
 (0)