1
0
Fork 0
editiCollaborativo/app_test.go

52 lines
987 B
Go
Raw Normal View History

2016-02-29 20:16:20 +01:00
package main
import (
. "github.com/franela/goblin"
2016-02-29 20:29:47 +01:00
"github.com/gin-gonic/gin"
2016-02-29 20:16:20 +01:00
"net/http"
"net/http/httptest"
"testing"
)
2016-03-01 19:14:44 +01:00
const Cookie = "Set-Cookie"
func client(method, path, session string) *httptest.ResponseRecorder {
2016-02-29 20:29:47 +01:00
gin.SetMode("test")
app := NewApp()
req, _ := http.NewRequest(method, path, nil)
2016-03-01 19:14:44 +01:00
if len(session) != 0 {
req.Header.Set(Cookie, session)
}
2016-02-29 20:16:20 +01:00
w := httptest.NewRecorder()
app.ServeHTTP(w, req)
return w
}
func Test(t *testing.T) {
g := Goblin(t)
g.Describe("App api", func() {
2016-03-01 19:14:44 +01:00
var session string
2016-02-29 20:16:20 +01:00
g.It("Should return 200 on / ", func() {
2016-03-01 19:14:44 +01:00
w := client("GET", "/", "")
2016-02-29 20:16:20 +01:00
g.Assert(w.Code).Equal(200)
2016-03-01 19:14:44 +01:00
session = w.HeaderMap.Get(Cookie)
2016-02-29 20:16:20 +01:00
})
g.It("Should return 200 on /slides.md ", func() {
2016-03-01 19:14:44 +01:00
w := client("GET", "/slides.md", session)
2016-02-29 20:16:20 +01:00
g.Assert(w.Code).Equal(200)
})
g.It("Should return 200 on PUT /slides.md ", func() {
2016-03-01 19:14:44 +01:00
w := client("PUT", "/slides.md", session)
2016-02-29 20:16:20 +01:00
g.Assert(w.Code).Equal(200)
})
g.It("Should works")
})
}