增加调试前端页面
This commit is contained in:
1 parent
3080b17d02
commit
ee9d2d7cf1
22 files changed
+1442
-59
No files matched your search
@@ -81,3 +81,44 @@ func TestRouterRegistersConfiguredDashScopeChatHandler(t *testing.T) {
|
||||
t.Fatalf("status = %d, want %d", response.Code, http.StatusAccepted)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRouterDoesNotExposeChatPageWithoutConfiguredHandler(t *testing.T) {
|
||||
for _, path := range []string{"/chat", "/chat/", "/chat/app.js", "/chat/app.css"} {
|
||||
request := httptest.NewRequest(http.MethodGet, path, nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewRouter().ServeHTTP(response, request)
|
||||
|
||||
if response.Code != http.StatusNotFound {
|
||||
t.Fatalf("%s status = %d, want %d", path, response.Code, http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRouterRegistersConfiguredChatPageHandler(t *testing.T) {
|
||||
page, err := NewChatPageHandler(ChatPageOptions{AppID: "fire-safety-app"})
|
||||
if err != nil {
|
||||
t.Fatalf("NewChatPageHandler() error = %v", err)
|
||||
}
|
||||
|
||||
request := httptest.NewRequest(http.MethodGet, "/chat/", nil)
|
||||
response := httptest.NewRecorder()
|
||||
NewRouter(RouterOptions{ChatPage: page}).ServeHTTP(response, request)
|
||||
if response.Code != http.StatusOK {
|
||||
t.Fatalf("/chat/ status = %d, want %d", response.Code, http.StatusOK)
|
||||
}
|
||||
|
||||
request = httptest.NewRequest(http.MethodGet, "/chat", nil)
|
||||
response = httptest.NewRecorder()
|
||||
NewRouter(RouterOptions{ChatPage: page}).ServeHTTP(response, request)
|
||||
if response.Code != http.StatusPermanentRedirect || response.Header().Get("Location") != "/chat/" {
|
||||
t.Fatalf("/chat status = %d location = %q, want redirect to /chat/", response.Code, response.Header().Get("Location"))
|
||||
}
|
||||
|
||||
request = httptest.NewRequest(http.MethodGet, "/chat/app.js", nil)
|
||||
response = httptest.NewRecorder()
|
||||
NewRouter(RouterOptions{ChatPage: page}).ServeHTTP(response, request)
|
||||
if response.Code != http.StatusOK || response.Header().Get("Content-Type") != "text/javascript; charset=utf-8" {
|
||||
t.Fatalf("/chat/app.js status = %d content-type = %q, want JavaScript 200", response.Code, response.Header().Get("Content-Type"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user