-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteapot_test.go
141 lines (114 loc) · 2.79 KB
/
teapot_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package jrdhttp_test
import (
"github.com/reiver/go-jrdhttp"
"fmt"
"io"
"net/http"
"net/http/httptest"
"testing"
)
func TestTeapot(t *testing.T) {
const expectedStatusCode = http.StatusTeapot
var rr *httptest.ResponseRecorder = httptest.NewRecorder()
var rw http.ResponseWriter = rr
jrdhttp.Teapot(rw)
var response *http.Response
{
response = rr.Result()
if nil == response {
t.Error("nil response")
return
}
}
{
var expected int = expectedStatusCode
var actual int = response.StatusCode
if expected != actual {
t.Error("the actual HTTP response status-code is not what was expected")
t.Logf("EXPECTED: %d", expected)
t.Logf("ACTUAL: %d", actual)
return
}
}
var headers http.Header
{
headers = rr.Header()
if nil == headers {
t.Error("did not expect headers to be nil, but actually was")
return
}
}
{
headerList, found := headers["Access-Control-Allow-Origin"]
if !found {
t.Error("Access-Control-Allow-Origin not header found")
return
}
{
const expected int = 1
var actual int = len(headerList)
if expected != actual {
t.Error("The actual number of Access-Control-Allow-Origin headers is not what was expected.")
t.Logf("EXPECTED: %d", expected)
t.Logf("ACTUAL: %d", actual)
return
}
}
header := headerList[0]
{
const expected string = "*"
var actual string = header
if expected != actual {
t.Error("The actual value for Access-Control-Allow-Origin is not what was expected")
t.Logf("EXPECTED: %q", expected)
t.Logf("ACTUAL: %q", actual)
return
}
}
}
var contentType string
{
contentTypes, found := headers["Content-Type"]
if !found {
t.Error("Content-Type header not found")
return
}
{
const expected int = 1
var actual int = len(contentTypes)
if expected != actual {
t.Error("The actual number of Content-Type headers is not what was expected.")
t.Logf("EXPECTED: %d", expected)
t.Logf("ACTUAL: %d", actual)
return
}
}
contentType = contentTypes[0]
}
{
const expected string = "application/jrd+json"
var actual string = contentType
if expected != actual {
t.Error("The actual value for Content-Type is not what was expected")
t.Logf("EXPECTED: %q", expected)
t.Logf("ACTUAL: %q", actual)
return
}
}
body, err := io.ReadAll(response.Body)
if nil != err {
t.Error("did not expect to get an error but actually got one")
t.Logf("ERROR: (%T) %q", err, err)
return
}
{
var expected string = fmt.Sprintf(`{"__http-response-status-code":"%d"}`, expectedStatusCode)
var actual string = string(body)
if expected != actual {
t.Error("The actual JRD value is not what was expected")
t.Logf("EXPECTED: %q", expected)
t.Logf("ACTUAL: %q", actual)
return
}
}
}