forked from ivpusic/httpcheck
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtester_header.go
60 lines (51 loc) · 1.72 KB
/
tester_header.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
package httpcheck
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// headers ///////////////////////////////////////////////////////
// WithHostHeader puts "Host" header on the request.
func (tt *Tester) WithHostHeader(value string) *Tester {
tt.request.Host = value
return tt
}
// WithHeader puts header on the request.
func (tt *Tester) WithHeader(key, value string) *Tester {
tt.request.Header.Set(key, value)
return tt
}
// WithHeaders puts a map of headers on the request.
func (tt *Tester) WithHeaders(headers map[string]string) *Tester {
for key, value := range headers {
tt.request.Header.Set(key, value)
}
return tt
}
// HasHeader checks if the response contains header on provided key with provided value.
func (tt *Tester) HasHeader(key, expectedValue string) *Tester {
value := tt.response.Header.Get(key)
assert.Exactly(tt.t, expectedValue, value)
return tt
}
// MustHasHeader checks if the response contains header on provided key with provided value.
func (tt *Tester) MustHasHeader(key, expectedValue string) *Tester {
value := tt.response.Header.Get(key)
require.Exactly(tt.t, expectedValue, value)
return tt
}
// HasHeaders checks if the response contains a provided headers map.
func (tt *Tester) HasHeaders(headers map[string]string) *Tester {
for key, expectedValue := range headers {
value := tt.response.Header.Get(key)
assert.Exactly(tt.t, expectedValue, value)
}
return tt
}
// MustHasHeaders checks if the response contains a provided headers map.
func (tt *Tester) MustHasHeaders(headers map[string]string) *Tester {
for key, expectedValue := range headers {
value := tt.response.Header.Get(key)
require.Exactly(tt.t, expectedValue, value)
}
return tt
}