forked from gobuffalo/packr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_box_test.go
82 lines (61 loc) · 1.67 KB
/
http_box_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
package packr
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func Test_HTTPBox(t *testing.T) {
r := require.New(t)
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(testBox))
req, err := http.NewRequest("GET", "/hello.txt", nil)
r.NoError(err)
res := httptest.NewRecorder()
mux.ServeHTTP(res, req)
r.Equal(200, res.Code)
r.Equal("hello world!", strings.TrimSpace(res.Body.String()))
}
// func Test_HTTPBox_CaseInsensitive(t *testing.T) {
//
// mux := http.NewServeMux()
// testBox.AddString("myfile.txt", "this is my file")
// mux.Handle("/", http.FileServer(testBox))
//
// for _, path := range []string{"/MyFile.txt", "/myfile.txt", "/Myfile.txt"} {
// t.Run(path, func(st *testing.T) {
// r := require.New(st)
//
// req, err := http.NewRequest("GET", path, nil)
// r.NoError(err)
//
// res := httptest.NewRecorder()
//
// mux.ServeHTTP(res, req)
//
// r.Equal(200, res.Code)
// r.Equal("this is my file", strings.TrimSpace(res.Body.String()))
// })
// }
// }
func Test_HTTPBox_NotFound(t *testing.T) {
r := require.New(t)
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(testBox))
req, err := http.NewRequest("GET", "/notInBox.txt", nil)
r.NoError(err)
res := httptest.NewRecorder()
mux.ServeHTTP(res, req)
r.Equal(404, res.Code)
}
func Test_HTTPBox_Handles_IndexHTML(t *testing.T) {
r := require.New(t)
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(testBox))
req, err := http.NewRequest("GET", "/", nil)
r.NoError(err)
res := httptest.NewRecorder()
mux.ServeHTTP(res, req)
r.Equal("<h1>Index!</h1>", strings.TrimSpace(res.Body.String()))
}