-
Notifications
You must be signed in to change notification settings - Fork 12
/
tck_test.go
52 lines (45 loc) · 938 Bytes
/
tck_test.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package wasm
import (
"context"
"net/http/httptest"
"testing"
"github.com/http-wasm/http-wasm-host-go/tck"
)
func TestTCK(t *testing.T) {
// Initialize the TCK guest wasm module.
mw, err := NewMiddleware(context.Background(), tck.GuestWASM)
if err != nil {
t.Fatal(err)
}
// Set the delegate handler of the middleware to the backend.
h := mw.NewHandler(context.Background(), tck.BackendHandler())
tests := []struct {
http2 bool
expected string
}{
{
http2: false,
expected: "HTTP/1.1",
},
{
http2: true,
expected: "HTTP/2.0",
},
}
for _, tt := range tests {
tc := tt
t.Run(tc.expected, func(t *testing.T) {
// Start the server.
ts := httptest.NewUnstartedServer(h)
if tc.http2 {
ts.EnableHTTP2 = true
ts.StartTLS()
} else {
ts.Start()
}
defer ts.Close()
// Run tests, issuing HTTP requests to server.
tck.Run(t, ts.Client(), ts.URL)
})
}
}