Akron | e216156 | 2022-12-19 17:05:39 +0100 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "net/http/httptest" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/stretchr/testify/assert" |
| 9 | ) |
| 10 | |
Akron | 5e1252e | 2022-12-19 17:57:56 +0100 | [diff] [blame] | 11 | func TestMappingRoute(t *testing.T) { |
Akron | e216156 | 2022-12-19 17:05:39 +0100 | [diff] [blame] | 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 | |
Akron | 6aee7fe | 2022-12-20 16:00:54 +0100 | [diff] [blame] | 27 | assert.Nil(t, add("s11", "s12", "s13", "sueddeutsche", "http://example.org")) |
Akron | e216156 | 2022-12-19 17:05:39 +0100 | [diff] [blame] | 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) |
Akron | 6aee7fe | 2022-12-20 16:00:54 +0100 | [diff] [blame] | 34 | assert.Equal(t, "sueddeutsche,http://example.org", w.Body.String()) |
Akron | e216156 | 2022-12-19 17:05:39 +0100 | [diff] [blame] | 35 | } |
Akron | 5e1252e | 2022-12-19 17:57:56 +0100 | [diff] [blame] | 36 | |
| 37 | func TestAssetRoute(t *testing.T) { |
| 38 | |
| 39 | router := setupRouter() |
| 40 | |
| 41 | w := httptest.NewRecorder() |
| 42 | req, _ := http.NewRequest(http.MethodGet, "/index", nil) |
| 43 | |
| 44 | router.ServeHTTP(w, req) |
| 45 | |
| 46 | assert.Equal(t, http.StatusOK, w.Code) |
| 47 | assert.Contains(t, w.Body.String(), "data-server=\"https://korap.ids-mannheim.de/\"") |
Akron | ebdfa00 | 2022-12-20 13:48:33 +0100 | [diff] [blame] | 48 | assert.Contains(t, w.Body.String(), "<title>External Provider</title>") |
Akron | 5e1252e | 2022-12-19 17:57:56 +0100 | [diff] [blame] | 49 | } |