This repository has been archived by the owner on Jun 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
unauthed_test.go
81 lines (64 loc) · 2.14 KB
/
unauthed_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
package tigerblood
import (
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"os"
"testing"
)
func TestLoadBalancerHeartbeatHandler(t *testing.T) {
h := HandleWithMiddleware(NewRouter(), []Middleware{})
req := httptest.NewRequest("GET", "/__lbheartbeat__", nil)
recorder := httptest.NewRecorder()
h.ServeHTTP(recorder, req)
res := recorder.Result()
assert.Equal(t, http.StatusOK, res.StatusCode)
}
func TestHeartbeatHandler(t *testing.T) {
dsn, found := os.LookupEnv("TIGERBLOOD_DSN")
assert.True(t, found)
db, err := NewDB(dsn)
assert.Nil(t, err)
SetDB(db)
h := HandleWithMiddleware(NewRouter(), []Middleware{})
req := httptest.NewRequest("GET", "/__heartbeat__", nil)
recorder := httptest.NewRecorder()
h.ServeHTTP(recorder, req)
res := recorder.Result()
assert.Equal(t, http.StatusOK, res.StatusCode)
}
func TestHeartbeatHandlerWithoutDB(t *testing.T) {
SetDB(nil)
h := HandleWithMiddleware(NewRouter(), []Middleware{})
req := httptest.NewRequest("GET", "/__heartbeat__", nil)
recorder := httptest.NewRecorder()
h.ServeHTTP(recorder, req)
res := recorder.Result()
assert.Equal(t, http.StatusInternalServerError, res.StatusCode)
}
func TestVersionHandler(t *testing.T) {
h := HandleWithMiddleware(NewRouter(), []Middleware{})
req := httptest.NewRequest("GET", "/__version__", nil)
recorder := httptest.NewRecorder()
h.ServeHTTP(recorder, req)
res := recorder.Result()
assert.Equal(t, http.StatusOK, res.StatusCode)
}
func TestDebugRoutesWhenProfileHandlersEnabled(t *testing.T) {
SetProfileHandlers(true)
h := HandleWithMiddleware(NewRouter(), []Middleware{})
req := httptest.NewRequest("GET", "/debug/pprof/", nil)
recorder := httptest.NewRecorder()
h.ServeHTTP(recorder, req)
res := recorder.Result()
assert.Equal(t, http.StatusOK, res.StatusCode)
}
func TestDebugRoutesWhenProfileHandlersDisabled(t *testing.T) {
SetProfileHandlers(false)
h := HandleWithMiddleware(NewRouter(), []Middleware{})
req := httptest.NewRequest("GET", "/debug/pprof/", nil)
recorder := httptest.NewRecorder()
h.ServeHTTP(recorder, req)
res := recorder.Result()
assert.Equal(t, http.StatusMovedPermanently, res.StatusCode)
}