app_test.go 838 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. func performRequest(method, path string) *httptest.ResponseRecorder {
  10. gin.SetMode("test")
  11. app := NewApp()
  12. req, _ := http.NewRequest(method, path, nil)
  13. w := httptest.NewRecorder()
  14. app.ServeHTTP(w, req)
  15. return w
  16. }
  17. func Test(t *testing.T) {
  18. g := Goblin(t)
  19. g.Describe("App api", func() {
  20. g.It("Should return 200 on / ", func() {
  21. w := performRequest("GET", "/")
  22. g.Assert(w.Code).Equal(200)
  23. })
  24. g.It("Should return 200 on /slides.md ", func() {
  25. w := performRequest("GET", "/slides.md")
  26. g.Assert(w.Code).Equal(200)
  27. })
  28. g.It("Should return 200 on PUT /slides.md ", func() {
  29. w := performRequest("PUT", "/slides.md")
  30. g.Assert(w.Code).Equal(200)
  31. })
  32. g.It("Should works")
  33. })
  34. }