This repository has been archived by the owner on Sep 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathapp_test.go
82 lines (65 loc) · 1.93 KB
/
app_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
. "github.com/franela/goblin"
"github.com/gin-gonic/gin"
)
const Cookie = "Set-Cookie"
func client(method, path, cookie string) *httptest.ResponseRecorder {
return request(method, path, cookie, "")
}
func request(method, path, cookie string, body string) *httptest.ResponseRecorder {
gin.SetMode("test")
app := NewApp()
payload := bytes.NewBufferString(body)
req, _ := http.NewRequest(method, path, payload)
if len(cookie) != 0 {
req.Header.Set("Cookie", cookie)
}
w := httptest.NewRecorder()
app.ServeHTTP(w, req)
return w
}
func Test(t *testing.T) {
g := Goblin(t)
g.Describe("App api", func() {
var cookie string
g.It("Should return 302 on / to redirect to file name ", func() {
w := client("GET", "/", "")
g.Assert(w.Code).Equal(302)
cookie = w.HeaderMap.Get(Cookie)
})
g.It("Should return 200 on /slides.md ", func() {
w := client("GET", "/slides.md", cookie)
g.Assert(w.Code).Equal(200)
})
g.It("Should return 200 on PUT /slides.md ", func() {
w := request("PUT", "/slides.md", cookie, "whatever")
g.Assert(w.Code).Equal(200)
})
g.It("Should return list of slides ", func() {
w := client("GET", "/stash", cookie)
g.Assert(w.Code).Equal(200)
})
g.It("Should return specific slide in preview", func() {
w := client("GET", "/published/slides/shy-cell.md", cookie)
g.Assert(w.Code).Equal(200)
})
g.It("Should return specific slide in edit mode", func() {
w := client("GET", "/stash/edit/shy-cell.md", cookie)
g.Assert(w.Code).Equal(200)
})
g.It("Should return specific slide in preview without session", func() {
w := client("GET", "/published/slides/shy-cell.md", "")
g.Assert(w.Code).Equal(200)
})
g.It("Should return specific slide in edit mode without session", func() {
w := client("GET", "/stash/edit/shy-cell.md", "")
g.Assert(w.Code).Equal(200)
})
g.It("Should works")
})
}