Skip to content

Commit 92d0b8d

Browse files
authored
Merge pull request #5 from adamreese/ref/test-examples
test: cleanup testing examples
2 parents 48ddef7 + a8a91f4 commit 92d0b8d

File tree

2 files changed

+23
-49
lines changed

2 files changed

+23
-49
lines changed

Makefile

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,6 @@ http/testdata/http-tinygo/main.wasm: generate
1616
http/testdata/http-tinygo/main.wasm: http/testdata/http-tinygo/main.go
1717
tinygo build -target=wasi -gc=leaking -no-debug -o http/testdata/http-tinygo/main.wasm http/testdata/http-tinygo/main.go
1818

19-
# ----------------------------------------------------------------------
20-
# Build examples
21-
# ----------------------------------------------------------------------
22-
EXAMPLES_DIR = examples
23-
24-
.PHONY: build-examples
25-
build-examples: generate
26-
build-examples: $(EXAMPLES_DIR)/http-tinygo-outbound-http/outbound-http-to-same-app/main.wasm
27-
build-examples: $(EXAMPLES_DIR)/http-tinygo-outbound-http/tinygo-hello/main.wasm
28-
build-examples: $(EXAMPLES_DIR)/http-tinygo/main.wasm
29-
build-examples: $(EXAMPLES_DIR)/tinygo-outbound-redis/main.wasm
30-
build-examples: $(EXAMPLES_DIR)/tinygo-redis/main.wasm
31-
build-examples: $(EXAMPLES_DIR)/tinygo-key-value/main.wasm
32-
build-examples: $(EXAMPLES_DIR)/tinygo-sqlite/main.wasm
33-
build-examples: $(EXAMPLES_DIR)/tinygo-llm/main.wasm
34-
build-examples: $(EXAMPLES_DIR)/tinygo-outbound-mysql/main.wasm
35-
build-examples: $(EXAMPLES_DIR)/tinygo-outbound-pg/main.wasm
36-
build-examples: $(EXAMPLES_DIR)/variables-tinygo/main.wasm
37-
38-
$(EXAMPLES_DIR)/%/main.wasm: $(EXAMPLES_DIR)/%/main.go
39-
tinygo build -target=wasi -gc=leaking -no-debug -o $@ $<
40-
4119
# ----------------------------------------------------------------------
4220
# Generate C bindings
4321
# ----------------------------------------------------------------------
@@ -117,14 +95,4 @@ clean:
11795
rm -f $(GENERATED_LLM)
11896
rm -f $(GENERATED_OUTBOUND_MYSQL)
11997
rm -f $(GENERATED_SDK_VERSION)
120-
rm -f http/testdata/http-tinygo/main.wasm
121-
rm -f $(EXAMPLES_DIR)/http-tinygo/main.wasm
122-
rm -f $(EXAMPLES_DIR)/http-tinygo-outbound-http/main.wasm
123-
rm -f $(EXAMPLES_DIR)/tinygo-outbound-redis/main.wasm
124-
rm -f $(EXAMPLES_DIR)/tinygo-redis/main.wasm
125-
rm -f $(EXAMPLES_DIR)/tinygo-key-value/main.wasm
126-
rm -f $(EXAMPLES_DIR)/tinygo-sqlite/main.wasm
127-
rm -f $(EXAMPLES_DIR)/tinygo-llm/main.wasm
128-
rm -f $(EXAMPLES_DIR)/tinygo-outbound-mysql/main.wasm
129-
rm -f $(EXAMPLES_DIR)/tinygo-outbound-pg/main.wasm
13098
rm -f $(SDK_VERSION_DEST_FILES)

integration_test.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"io"
88
"net"
99
"net/http"
10+
"os"
1011
"os/exec"
12+
"path/filepath"
1113
"testing"
1214
"time"
1315
)
@@ -40,13 +42,16 @@ type testSpin struct {
4042
cmd *exec.Cmd
4143
}
4244

43-
func startSpin(t *testing.T, spinfile string) *testSpin {
44-
// long timeout because... ci
45-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
45+
func startSpin(t *testing.T, dir string) *testSpin {
46+
buildApp(t, dir)
4647

4748
url := getFreePort(t)
4849

49-
cmd := exec.CommandContext(ctx, spinBinary, "up", "--build", "--file", spinfile, "--listen", url)
50+
// long timeout because... ci
51+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
52+
53+
cmd := exec.CommandContext(ctx, spinBinary, "up", "--listen", url)
54+
cmd.Dir = dir
5055
stderr := new(bytes.Buffer)
5156
cmd.Stderr = stderr
5257
if err := cmd.Start(); err != nil {
@@ -70,10 +75,10 @@ func startSpin(t *testing.T, spinfile string) *testSpin {
7075
}
7176
}
7277

73-
func build(t *testing.T, dir string) {
78+
func buildApp(t *testing.T, dir string) {
7479
t.Helper()
7580

76-
t.Log("building example: ", dir)
81+
t.Log("building application:", dir)
7782

7883
cmd := exec.Command(spinBinary, "build")
7984
cmd.Dir = dir
@@ -87,7 +92,7 @@ func build(t *testing.T, dir string) {
8792
}
8893

8994
func TestSpinRoundTrip(t *testing.T) {
90-
spin := startSpin(t, "http/testdata/spin-roundtrip/spin.toml")
95+
spin := startSpin(t, "http/testdata/spin-roundtrip")
9196
defer spin.cancel()
9297

9398
resp := retryGet(t, spin.url+"/hello")
@@ -111,7 +116,7 @@ func TestSpinRoundTrip(t *testing.T) {
111116
}
112117

113118
func TestHTTPTriger(t *testing.T) {
114-
spin := startSpin(t, "http/testdata/http-tinygo/spin.toml")
119+
spin := startSpin(t, "http/testdata/http-tinygo")
115120
defer spin.cancel()
116121

117122
resp := retryGet(t, spin.url+"/hello")
@@ -141,15 +146,16 @@ func TestHTTPTriger(t *testing.T) {
141146

142147
// TestBuildExamples ensures that the tinygo examples will build successfully.
143148
func TestBuildExamples(t *testing.T) {
144-
for _, example := range []string{
145-
"examples/http-tinygo",
146-
"examples/http-tinygo-outbound-http",
147-
"examples/tinygo-outbound-redis",
148-
"examples/tinygo-redis",
149-
"examples/tinygo-key-value",
150-
"examples/variables-tinygo",
151-
} {
152-
build(t, example)
149+
examples, err := os.ReadDir("examples")
150+
if err != nil {
151+
t.Fatal(err)
152+
}
153+
for _, example := range examples {
154+
example := example
155+
t.Run(example.Name(), func(t *testing.T) {
156+
t.Parallel()
157+
buildApp(t, filepath.Join("examples", example.Name()))
158+
})
153159
}
154160
}
155161

0 commit comments

Comments
 (0)