This commit is contained in:
Alex Myasoedov 2016-02-29 21:29:47 +02:00
parent 50a780483f
commit e341b3fd8d
2 changed files with 17 additions and 9 deletions

View file

@ -2,14 +2,16 @@ package main
import (
. "github.com/franela/goblin"
"github.com/gin-gonic/gin"
"net/http"
"net/http/httptest"
"testing"
)
func performRequest(method, path string) *httptest.ResponseRecorder {
app := NewApp()
req, _ := http.NewRequest(method, path, nil)
gin.SetMode("test")
app := NewApp()
req, _ := http.NewRequest(method, path, nil)
w := httptest.NewRecorder()
app.ServeHTTP(w, req)
return w
@ -20,17 +22,17 @@ func Test(t *testing.T) {
g.Describe("App api", func() {
g.It("Should return 200 on / ", func() {
w := performRequest("GET", "/")
w := performRequest("GET", "/")
g.Assert(w.Code).Equal(200)
})
g.It("Should return 200 on /slides.md ", func() {
w := performRequest("GET", "/slides.md")
w := performRequest("GET", "/slides.md")
g.Assert(w.Code).Equal(200)
})
g.It("Should return 200 on PUT /slides.md ", func() {
w := performRequest("PUT", "/slides.md")
w := performRequest("PUT", "/slides.md")
g.Assert(w.Code).Equal(200)
})

14
main.go
View file

@ -11,6 +11,14 @@ func NewApp() *gin.Engine {
r := gin.Default()
r.LoadHTMLGlob("templates/*.tmpl")
r.GET("/", func(c *gin.Context) {
c.HTML(200, "index.tmpl", gin.H{
"pubTo": "Users",
})
})
r.GET("/slides.md", func(c *gin.Context) {
body, err := ioutil.ReadFile("initial-slides.md")
if err != nil {
@ -19,10 +27,8 @@ func NewApp() *gin.Engine {
c.String(200, string(body))
})
r.GET("/", func(c *gin.Context) {
c.HTML(200, "index.tmpl", gin.H{
"pubTo": "Users",
})
r.PUT("/slides.md", func(c *gin.Context) {
c.String(403, "")
})
// Get user value