-
Notifications
You must be signed in to change notification settings - Fork 158
/
util_test.go
55 lines (47 loc) · 1.13 KB
/
util_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
package main
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
func Test_formatBaseURL(t *testing.T) {
var tests = []struct {
input []string
output string
}{
{
[]string{"http://example.com", "/tiles"},
"http://example.com/tiles",
},
{
[]string{"http://example.com", "tiles"},
"http://example.com/tiles",
},
{
[]string{"http://example.com/", "/tiles/"},
"http://example.com/tiles",
},
{
[]string{"https://example.com/", "/"},
"https://example.com",
},
}
for _, test := range tests {
if output := formatBaseURL(test.input[0], test.input[1]); output != test.output {
t.Errorf("Test failed: input: %v, expected: %s, recieved: %s", test.input, test.output, output)
}
}
}
func TestMetrics(t *testing.T) {
if !dbsetup {
t.Skip("DB integration test suite setup failed, skipping")
}
viper.Set("EnableMetrics", true)
r := tileRouter()
request, _ := http.NewRequest("GET", "/metrics", nil)
response := httptest.NewRecorder()
r.ServeHTTP(response, request)
assert.Equal(t, 200, response.Code, "OK response is expected")
}