1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/go-baa-baa

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
static_test.go 1.7 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
coldstar Отправлено 10.10.2016 13:56 7feed6b
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)
})
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/go-baa-baa.git
git@api.gitlife.ru:oschina-mirror/go-baa-baa.git
oschina-mirror
go-baa-baa
go-baa-baa
master