diff --git a/app_test.go b/app_test.go index 8ed18a2..a7a1449 100644 --- a/app_test.go +++ b/app_test.go @@ -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) }) diff --git a/main.go b/main.go index 14e9f9d..5d8af2c 100644 --- a/main.go +++ b/main.go @@ -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