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
8994func 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
113118func 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.
143148func 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