(t *testing.T)
| 95 | } |
| 96 | |
| 97 | func TestShortLinkMatcher_AddDelRoute(t *testing.T) { |
| 98 | ep := NewEntrypoint(task.GetTestTask(t), nil) |
| 99 | matcher := ep.ShortLinkMatcher() |
| 100 | matcher.SetDefaultDomainSuffix(".example.com") |
| 101 | |
| 102 | matcher.AddRoute("app1") |
| 103 | matcher.AddRoute("app2.domain.com") |
| 104 | |
| 105 | t.Run("both routes work", func(t *testing.T) { |
| 106 | req := httptest.NewRequest(http.MethodGet, "/app1", nil) |
| 107 | w := httptest.NewRecorder() |
| 108 | matcher.ServeHTTP(w, req) |
| 109 | assert.Equal(t, http.StatusTemporaryRedirect, w.Code) |
| 110 | assert.Equal(t, "https://app1.example.com/", w.Header().Get("Location")) |
| 111 | |
| 112 | req = httptest.NewRequest(http.MethodGet, "/app2.domain.com", nil) |
| 113 | w = httptest.NewRecorder() |
| 114 | matcher.ServeHTTP(w, req) |
| 115 | assert.Equal(t, http.StatusTemporaryRedirect, w.Code) |
| 116 | assert.Equal(t, "https://app2.domain.com/", w.Header().Get("Location")) |
| 117 | }) |
| 118 | |
| 119 | t.Run("delete route", func(t *testing.T) { |
| 120 | matcher.DelRoute("app1") |
| 121 | |
| 122 | req := httptest.NewRequest(http.MethodGet, "/app1", nil) |
| 123 | w := httptest.NewRecorder() |
| 124 | matcher.ServeHTTP(w, req) |
| 125 | assert.Equal(t, http.StatusNotFound, w.Code) |
| 126 | |
| 127 | req = httptest.NewRequest(http.MethodGet, "/app2.domain.com", nil) |
| 128 | w = httptest.NewRecorder() |
| 129 | matcher.ServeHTTP(w, req) |
| 130 | assert.Equal(t, http.StatusTemporaryRedirect, w.Code) |
| 131 | assert.Equal(t, "https://app2.domain.com/", w.Header().Get("Location")) |
| 132 | }) |
| 133 | } |
| 134 | |
| 135 | func TestShortLinkMatcher_NoDefaultDomainSuffix(t *testing.T) { |
| 136 | ep := NewEntrypoint(task.GetTestTask(t), nil) |
nothing calls this directly
no test coverage detected