blob: a18c52eb49544616149fc2f180a3f20358a25f18 [file] [log] [blame]
Akrone2161562022-12-19 17:05:39 +01001package main
2
3import (
4 "net/http"
5 "net/http/httptest"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9)
10
11func TestPingRoute(t *testing.T) {
12
13 dir := t.TempDir()
14
15 initDB(dir)
16 defer closeDB()
17 router := setupRouter()
18
19 w := httptest.NewRecorder()
20 req, _ := http.NewRequest(http.MethodGet, "/s10/s10/s10", nil)
21
22 router.ServeHTTP(w, req)
23
24 assert.Equal(t, http.StatusNotFound, w.Code)
25 assert.Equal(t, "No entry found", w.Body.String())
26
27 assert.Nil(t, add("s11", "s12", "s13", "http://example.org"))
28
29 w = httptest.NewRecorder()
30 req, _ = http.NewRequest(http.MethodGet, "/s11/s12/s13", nil)
31
32 router.ServeHTTP(w, req)
33 assert.Equal(t, http.StatusOK, w.Code)
34 assert.Equal(t, "http://example.org", w.Body.String())
35}