-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
header_test.go
32 lines (26 loc) · 1.09 KB
/
header_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
package handlertest
import (
"github.com/krzysztofmadejski/handlertest/internal"
"net/http"
"testing"
)
var expectHeader = func(t *testing.T, header string, expectedValue string) http.HandlerFunc {
at := internal.CallerInfo()[1]
return func(w http.ResponseWriter, r *http.Request) {
value := r.Header.Get(header)
if expectedValue != "" && value == "" {
t.Errorf("Expected Header %s set to %s, but it is empty \nat %v", header, expectedValue, at)
} else if expectedValue == "" && value != "" {
t.Errorf("Expected Header %s to be empty, but got %s \nat %v", header, value, at)
} else if expectedValue != value {
t.Errorf("Expected Header %s set to %s, got %s \nat %v", header, expectedValue, value, at)
}
}
}
func TestHeader(t *testing.T) {
Call(expectHeader(t, "Allow-Origin", "*")).Header("Allow-Origin", "*").Assert(new(testing.T))
Call(expectHeader(t, "Allow-Origin", "")).Header("Content-Type", "text/plain").Assert(new(testing.T))
}
func TestContentType(t *testing.T) {
Call(expectHeader(t, "Content-Type", "text/plain")).ContentType("text/plain").Assert(new(testing.T))
}