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 | 906a2c5 | 2022-12-21 11:35:28 +0100 | [diff] [blame^] | 35 | |
| 36 | w = httptest.NewRecorder() |
| 37 | req, _ = http.NewRequest(http.MethodGet, "/s11/s12/s14", nil) |
| 38 | |
| 39 | router.ServeHTTP(w, req) |
| 40 | assert.Equal(t, http.StatusNotFound, w.Code) |
| 41 | assert.Equal(t, "No entry found", w.Body.String()) |
Akron | e216156 | 2022-12-19 17:05:39 +0100 | [diff] [blame] | 42 | } |
Akron | 5e1252e | 2022-12-19 17:57:56 +0100 | [diff] [blame] | 43 | |
| 44 | func TestAssetRoute(t *testing.T) { |
| 45 | |
| 46 | router := setupRouter() |
| 47 | |
| 48 | w := httptest.NewRecorder() |
Akron | f1adbe0 | 2022-12-21 10:32:21 +0100 | [diff] [blame] | 49 | req, _ := http.NewRequest(http.MethodGet, "/", nil) |
Akron | 5e1252e | 2022-12-19 17:57:56 +0100 | [diff] [blame] | 50 | |
| 51 | router.ServeHTTP(w, req) |
| 52 | |
| 53 | assert.Equal(t, http.StatusOK, w.Code) |
Akron | f1adbe0 | 2022-12-21 10:32:21 +0100 | [diff] [blame] | 54 | assert.Contains(t, w.Body.String(), "data-server=\"https://korap.ids-mannheim.de/instance/test\"") |
Akron | ebdfa00 | 2022-12-20 13:48:33 +0100 | [diff] [blame] | 55 | assert.Contains(t, w.Body.String(), "<title>External Provider</title>") |
Akron | 5e1252e | 2022-12-19 17:57:56 +0100 | [diff] [blame] | 56 | } |