-
Notifications
You must be signed in to change notification settings - Fork 51
/
http3_test.go
50 lines (45 loc) · 1.36 KB
/
http3_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
package netemx
import (
"net/http"
"testing"
"github.com/apex/log"
"github.com/google/go-cmp/cmp"
"github.com/ooni/netem"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)
func TestHTTP3ServerFactory(t *testing.T) {
t.Run("when using the TLSConfig provided by netem", func(t *testing.T) {
env := MustNewQAEnv(
QAEnvOptionNetStack(AddressWwwExampleCom, &HTTP3ServerFactory{
Factory: HTTPHandlerFactoryFunc(func(env NetStackServerFactoryEnv, stack *netem.UNetStack) http.Handler {
return ExampleWebPageHandler()
}),
Ports: []int{443},
ServerNameMain: "www.example.com",
}),
)
defer env.Close()
env.AddRecordToAllResolvers("www.example.com", "", AddressWwwExampleCom)
env.Do(func() {
netx := &netxlite.Netx{}
client := netxlite.NewHTTP3ClientWithResolver(netx, log.Log, netx.NewStdlibResolver(log.Log))
req := runtimex.Try1(http.NewRequest("GET", "https://www.example.com/", nil))
resp, err := client.Do(req)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
t.Fatal("unexpected StatusCode", resp.StatusCode)
}
data, err := netxlite.ReadAllContext(req.Context(), resp.Body)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(ExampleWebPage, string(data)); diff != "" {
t.Fatal(diff)
}
})
})
}