app_test.go 987 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. . "github.com/franela/goblin"
  4. "github.com/gin-gonic/gin"
  5. "net/http"
  6. "net/http/httptest"
  7. "testing"
  8. )
  9. const Cookie = "Set-Cookie"
  10. func client(method, path, session string) *httptest.ResponseRecorder {
  11. gin.SetMode("test")
  12. app := NewApp()
  13. req, _ := http.NewRequest(method, path, nil)
  14. if len(session) != 0 {
  15. req.Header.Set(Cookie, session)
  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 session string
  25. g.It("Should return 200 on / ", func() {
  26. w := client("GET", "/", "")
  27. g.Assert(w.Code).Equal(200)
  28. session = w.HeaderMap.Get(Cookie)
  29. })
  30. g.It("Should return 200 on /slides.md ", func() {
  31. w := client("GET", "/slides.md", session)
  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", session)
  36. g.Assert(w.Code).Equal(200)
  37. })
  38. g.It("Should works")
  39. })
  40. }