Tests
This commit is contained in:
parent
50a780483f
commit
e341b3fd8d
2 changed files with 17 additions and 9 deletions
12
app_test.go
12
app_test.go
|
@ -2,14 +2,16 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "github.com/franela/goblin"
|
. "github.com/franela/goblin"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func performRequest(method, path string) *httptest.ResponseRecorder {
|
func performRequest(method, path string) *httptest.ResponseRecorder {
|
||||||
app := NewApp()
|
gin.SetMode("test")
|
||||||
req, _ := http.NewRequest(method, path, nil)
|
app := NewApp()
|
||||||
|
req, _ := http.NewRequest(method, path, nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
app.ServeHTTP(w, req)
|
app.ServeHTTP(w, req)
|
||||||
return w
|
return w
|
||||||
|
@ -20,17 +22,17 @@ func Test(t *testing.T) {
|
||||||
g.Describe("App api", func() {
|
g.Describe("App api", func() {
|
||||||
|
|
||||||
g.It("Should return 200 on / ", func() {
|
g.It("Should return 200 on / ", func() {
|
||||||
w := performRequest("GET", "/")
|
w := performRequest("GET", "/")
|
||||||
g.Assert(w.Code).Equal(200)
|
g.Assert(w.Code).Equal(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Should return 200 on /slides.md ", func() {
|
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.Assert(w.Code).Equal(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Should return 200 on PUT /slides.md ", func() {
|
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)
|
g.Assert(w.Code).Equal(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
14
main.go
14
main.go
|
@ -11,6 +11,14 @@ func NewApp() *gin.Engine {
|
||||||
|
|
||||||
r := gin.Default()
|
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) {
|
r.GET("/slides.md", func(c *gin.Context) {
|
||||||
body, err := ioutil.ReadFile("initial-slides.md")
|
body, err := ioutil.ReadFile("initial-slides.md")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,10 +27,8 @@ func NewApp() *gin.Engine {
|
||||||
c.String(200, string(body))
|
c.String(200, string(body))
|
||||||
})
|
})
|
||||||
|
|
||||||
r.GET("/", func(c *gin.Context) {
|
r.PUT("/slides.md", func(c *gin.Context) {
|
||||||
c.HTML(200, "index.tmpl", gin.H{
|
c.String(403, "")
|
||||||
"pubTo": "Users",
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Get user value
|
// Get user value
|
||||||
|
|
Loading…
Reference in a new issue