app_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package main
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "testing"
  6. . "github.com/franela/goblin"
  7. "github.com/gin-gonic/gin"
  8. )
  9. const Cookie = "Set-Cookie"
  10. func client(method, path, cookie string) *httptest.ResponseRecorder {
  11. gin.SetMode("test")
  12. app := NewApp()
  13. req, _ := http.NewRequest(method, path, nil)
  14. if len(cookie) != 0 {
  15. req.Header.Set("Cookie", cookie)
  16. }
  17. w := httptest.NewRecorder()
  18. app.ServeHTTP(w, req)
  19. return w
  20. }
  21. func Test(t *testing.T) {
  22. g := Goblin(t)
  23. g.Describe("App api", func() {
  24. var cookie string
  25. g.It("Should return 200 on / ", func() {
  26. w := client("GET", "/", "")
  27. g.Assert(w.Code).Equal(200)
  28. cookie = w.HeaderMap.Get(Cookie)
  29. })
  30. g.It("Should return 200 on /slides.md ", func() {
  31. w := client("GET", "/slides.md", cookie)
  32. g.Assert(w.Code).Equal(200)
  33. })
  34. g.It("Should return 200 on PUT /slides.md ", func() {
  35. w := client("PUT", "/slides.md", cookie)
  36. g.Assert(w.Code).Equal(200)
  37. })
  38. g.It("Should return list of slides ", func() {
  39. w := client("GET", "/stash", cookie)
  40. g.Assert(w.Code).Equal(200)
  41. })
  42. g.It("Should return specific slide in preview", func() {
  43. w := client("GET", "/published/shy-cell.md", cookie)
  44. g.Assert(w.Code).Equal(200)
  45. })
  46. g.It("Should return specific slide in edit mode", func() {
  47. w := client("GET", "/stash/edit/shy-cell.md", cookie)
  48. g.Assert(w.Code).Equal(200)
  49. })
  50. g.It("Should works")
  51. })
  52. }