-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathtls_test.go
90 lines (69 loc) · 1.76 KB
/
tls_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
78
79
80
81
82
83
84
85
86
87
88
89
90
package examples
import (
"crypto/tls"
"net/http"
"strconv"
"testing"
"github.com/gavv/httpexpect/v2"
)
func TLSClient() *http.Client {
cfg := tls.Config{RootCAs: NewRootCertPool()}
return &http.Client{Transport: &http.Transport{TLSClientConfig: &cfg}}
}
func TestExampleTlsServer(t *testing.T) {
server := ExampleTLSServer()
server.StartTLS()
defer server.Close()
config := httpexpect.Config{
BaseURL: server.URL, Client: TLSClient(),
Reporter: httpexpect.NewRequireReporter(t),
Printers: []httpexpect.Printer{
httpexpect.NewDebugPrinter(t, true),
}}
e := httpexpect.WithConfig(config)
e.PUT("/tls/car").WithText("1").
Expect().
Status(http.StatusNoContent).NoContent()
e.PUT("/tls/car").WithText("10").
Expect().
Status(http.StatusNoContent).NoContent()
e.GET("/tls/car").
Expect().
Status(http.StatusOK).Body().IsEqual("11")
e.DELETE("/tls/car").WithText("1").
Expect().
Status(http.StatusNoContent).NoContent()
e.GET("/tls/car").
Expect().
Status(http.StatusOK).Body().IsEqual("10")
e.GET("/tls/not_there").
Expect().
Status(http.StatusNotFound).NoContent()
e.DELETE("/tls/car").WithText("10").
Expect().
Status(http.StatusNoContent).NoContent()
items := map[string]int{
"car": 2,
"house": 1,
"cat": 6,
"fridge": 3,
}
for item, amount := range items {
e.PUT("/tls/" + item).WithText(strconv.Itoa(amount)).
Expect().
Status(http.StatusNoContent).NoContent()
}
e.DELETE("/tls/car").WithText("1").
Expect().
Status(http.StatusNoContent).NoContent()
items["car"]--
var m map[string]int
r := e.GET("/tls").Expect().Status(http.StatusOK)
r.Header("Content-Type").IsEqual("application/json")
r.JSON().Decode(&m)
for item, amount := range m {
if amount != items[item] {
t.Fail()
}
}
}