-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil_test.go
77 lines (63 loc) · 1.15 KB
/
util_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"io/ioutil"
"net/http"
"net/url"
"os"
"time"
"github.com/lucas-clemente/quic-go/h2quic"
)
const (
addrListened = "https://127.0.0.1:28443"
)
func createTmpFile(content string) (f *os.File, fn string) {
tmpfile, err := ioutil.TempFile("", "quick")
if err != nil {
panic(err)
}
if _, err := tmpfile.Write([]byte(content)); err != nil {
panic(err)
}
if err := tmpfile.Close(); err != nil {
panic(err)
}
return tmpfile, tmpfile.Name()
}
func createTmpDir() (dir string) {
dir, err := ioutil.TempDir("", "quick")
if err != nil {
panic(err)
}
return dir
}
var (
tlsCfg = generateTLSConfig()
)
func startServer(handler http.Handler) chan struct{} {
done := make(chan struct{})
go func() {
netAddr, err := url.Parse(addrListened)
if err != nil {
panic(err)
}
server := &h2quic.Server{
Server: &http.Server{
Addr: netAddr.Host,
Handler: handler,
},
}
server.TLSConfig = tlsCfg
go func() {
server.Serve(nil)
}()
<-done
err = server.Close()
if err != nil {
panic(err)
}
close(done)
}()
// ensure server is started
time.Sleep(50 * time.Millisecond)
return done
}