-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
85 lines (63 loc) · 2.13 KB
/
main_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
83
84
85
package main
import (
"io"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
test "github.com/thbkrkr/go-apish/test"
)
var (
server *httptest.Server
reader io.Reader //Ignore this for now
)
var auth = &test.BasicAuth{"zuperadmin", "42"}
func init() {
gin.SetMode(gin.TestMode)
*apiDir = "example/api"
*password = "42"
server = httptest.NewServer(Router())
test.ServerURL = server.URL
}
func TestBase(t *testing.T) {
test.PrefixURL = ""
status, _ := test.Get(t, "/", nil)
assert.Equal(t, 200, status, "should get a 200")
status, _ = test.Get(t, "/favicon.ico", nil)
assert.Equal(t, 200, status, "should get a 200")
status, _ = test.Get(t, "/blablabla", nil)
assert.Equal(t, 404, status, "should get a 404")
}
func TestAuthentication(t *testing.T) {
status, _ := test.Get(t, "/api/time/date", nil)
assert.Equal(t, 401, status, "should get a 401")
auth := &test.BasicAuth{"zuperadmin", "42"}
status, _ = test.Get(t, "/api/time/date", auth)
assert.Equal(t, 200, status, "should get a 200")
apiKey := new(string)
*apiKey = "42"
status, _ = test.Get2(t, "/api/time/date", apiKey)
assert.Equal(t, 200, status, "should get a 200")
}
func TestScripts(t *testing.T) {
status, _ := test.Get(t, "/api/nothing", auth)
assert.Equal(t, 404, status, "should get a 404")
status, _ = test.Get(t, "/api/time/date", auth)
assert.Equal(t, 200, status, "should get a 200")
status, _ = test.Get(t, "/api/test/param?q=hello", auth)
assert.Equal(t, 200, status, "should get a 200")
status, _ = test.Get(t, "/api/time/date", auth)
assert.Equal(t, 200, status, "should get a 200")
}
func TestPages(t *testing.T) {
status, _ := test.Get(t, "/s/", auth)
assert.Equal(t, 200, status, "should get a 200")
status, _ = test.Get(t, "/s/date.html", auth)
assert.Equal(t, 200, status, "should get a 200")
status, _ = test.Get(t, "/s/css/styles.css", auth)
assert.Equal(t, 200, status, "should get a 200")
status, _ = test.Get(t, "/s/css/styles.css", auth)
assert.Equal(t, 200, status, "should get a 200")
status, _ = test.Get(t, "/s/js/script.js", auth)
assert.Equal(t, 200, status, "should get a 200")
}