blob: eee7a79d38f4d552ce59ef703847e5829b6e6e2e [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
Akron5e1252e2022-12-19 17:57:56 +010011func TestMappingRoute(t *testing.T) {
Akrone2161562022-12-19 17:05:39 +010012
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
Akron6aee7fe2022-12-20 16:00:54 +010027 assert.Nil(t, add("s11", "s12", "s13", "sueddeutsche", "http://example.org"))
Akrone2161562022-12-19 17:05:39 +010028
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)
Akron6aee7fe2022-12-20 16:00:54 +010034 assert.Equal(t, "sueddeutsche,http://example.org", w.Body.String())
Akrone2161562022-12-19 17:05:39 +010035}
Akron5e1252e2022-12-19 17:57:56 +010036
37func TestAssetRoute(t *testing.T) {
38
39 router := setupRouter()
40
41 w := httptest.NewRecorder()
Akronf1adbe02022-12-21 10:32:21 +010042 req, _ := http.NewRequest(http.MethodGet, "/", nil)
Akron5e1252e2022-12-19 17:57:56 +010043
44 router.ServeHTTP(w, req)
45
46 assert.Equal(t, http.StatusOK, w.Code)
Akronf1adbe02022-12-21 10:32:21 +010047 assert.Contains(t, w.Body.String(), "data-server=\"https://korap.ids-mannheim.de/instance/test\"")
Akronebdfa002022-12-20 13:48:33 +010048 assert.Contains(t, w.Body.String(), "<title>External Provider</title>")
Akron5e1252e2022-12-19 17:57:56 +010049}