-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_utils.go
49 lines (42 loc) · 924 Bytes
/
test_utils.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
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func apiServer(t testing.TB, path string, resp string, test func()) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != path {
t.Errorf("Wrong URL: %v", r.URL.String())
return
}
w.WriteHeader(200)
fmt.Fprintln(w, resp)
}))
u, err := url.Parse(server.URL)
if err != nil {
panic(err)
}
GodoBase = u
defer server.Close()
test()
}
func metadataServer(t testing.TB, path string, resp string, test func()) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != path {
t.Errorf("Wrong URL: %v", r.URL.String())
return
}
w.WriteHeader(200)
fmt.Fprintln(w, resp)
}))
u, err := url.Parse(server.URL)
if err != nil {
panic(err)
}
MetadataBase = u
defer server.Close()
test()
}