MCPcopy
hub / github.com/yusing/godoxy / TestShortLinkMatcher_AddDelRoute

Function TestShortLinkMatcher_AddDelRoute

internal/entrypoint/shortlink_test.go:97–133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func 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
135func TestShortLinkMatcher_NoDefaultDomainSuffix(t *testing.T) {
136 ep := NewEntrypoint(task.GetTestTask(t), nil)

Callers

nothing calls this directly

Calls 8

ShortLinkMatcherMethod · 0.95
NewEntrypointFunction · 0.85
AddRouteMethod · 0.65
ServeHTTPMethod · 0.65
GetMethod · 0.65
DelRouteMethod · 0.65
HeaderMethod · 0.45

Tested by

no test coverage detected