-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathprocess_test.go
38 lines (33 loc) · 1002 Bytes
/
process_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
package webseclab
import (
"net/http"
"testing"
)
// mock for http.ResponseWriter is in common_test.go
// create a type for brevity and to avoid repetition in testing two similar functions
type dohandler func(w http.ResponseWriter, fpath string, input *InData) (err error)
// read the templates
func init() {
err := parseTemplates()
if err != nil {
panic(err)
}
}
// Test that doHtmlTemplate sets correct content-type
func TestTemplateContentType(t *testing.T) {
t.Parallel()
funcs := [...]dohandler{doHTMLTemplate, doTextTemplate}
funcnames := [...]string{`doHtmlTemplate`, `doTextTemplate`}
for i, f := range funcs {
w := newMockResponseWriter()
input := &InData{}
err := f(w, "xss/reflect/basic", input)
if err != nil {
t.Errorf("Error in %s: %s\n", funcnames[i], err)
return
}
if ctype := w.Header().Get("Content-Type"); ctype != "text/html; charset=utf-8" {
t.Errorf("Unexpected ctype in %s %s - want text/html; charset=utf-8\n", funcnames[i], ctype)
}
}
}