-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathstatic_test.go
70 lines (61 loc) · 1.7 KB
/
static_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
package baa
import (
"net/http"
"net/http/httptest"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestStaticRoute1(t *testing.T) {
Convey("static serve register", t, func() {
Convey("register without slash", func() {
b.Static("/static", "./_fixture", false, f)
})
Convey("register with slash", func() {
b.Static("/assets/", "./_fixture/", true, f)
})
Convey("register with empty path", func() {
b2 := New()
defer func() {
e := recover()
So(e, ShouldNotBeNil)
}()
b2.Static("", "./_fixture/", true, f)
})
Convey("register with empty dir", func() {
b2 := New()
defer func() {
e := recover()
So(e, ShouldNotBeNil)
}()
b2.Static("/static", "", true, f)
})
})
}
func TestStaticServe(t *testing.T) {
Convey("static serve request", t, func() {
req, _ := http.NewRequest("GET", "/static", nil)
w := httptest.NewRecorder()
b.ServeHTTP(w, req)
So(w.Code, ShouldEqual, http.StatusForbidden)
req, _ = http.NewRequest("GET", "/assets/", nil)
w = httptest.NewRecorder()
b.ServeHTTP(w, req)
So(w.Code, ShouldEqual, http.StatusOK)
req, _ = http.NewRequest("GET", "/assets/img", nil)
w = httptest.NewRecorder()
b.ServeHTTP(w, req)
So(w.Code, ShouldEqual, http.StatusFound)
req, _ = http.NewRequest("GET", "/static/index1.html", nil)
w = httptest.NewRecorder()
b.ServeHTTP(w, req)
So(w.Code, ShouldEqual, http.StatusOK)
req, _ = http.NewRequest("GET", "/static/favicon.ico", nil)
w = httptest.NewRecorder()
b.ServeHTTP(w, req)
So(w.Code, ShouldEqual, http.StatusOK)
req, _ = http.NewRequest("GET", "/static/notfound", nil)
w = httptest.NewRecorder()
b.ServeHTTP(w, req)
So(w.Code, ShouldEqual, http.StatusNotFound)
})
}