Files
scrabble-game/gateway/internal/connectsrv/console_mount_test.go
T
developer 3a640a17a4
Tests · Go / test (push) Successful in 7s
Tests · Integration / integration (push) Successful in 13s
Stage 10: admin console & dictionary ops (complaint review, hot-reload, broadcasts) (#11)
2026-06-04 07:27:49 +00:00

46 lines
1.3 KiB
Go

package connectsrv_test
import (
"net/http"
"net/http/httptest"
"testing"
"scrabble/gateway/internal/connectsrv"
)
// TestHTTPHandlerMountsAdminConsole verifies the admin proxy is reachable at /_gm/
// through the h2c-wrapped edge mux when configured.
func TestHTTPHandlerMountsAdminConsole(t *testing.T) {
stub := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusTeapot)
})
srv := connectsrv.NewServer(connectsrv.Deps{AdminProxy: stub})
front := httptest.NewServer(srv.HTTPHandler())
defer front.Close()
resp, err := http.Get(front.URL + "/_gm/")
if err != nil {
t.Fatal(err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusTeapot {
t.Fatalf("/_gm status = %d, want 418 (routed to the admin proxy)", resp.StatusCode)
}
}
// TestHTTPHandlerNoAdminConsole verifies /_gm is not served when no proxy is set.
func TestHTTPHandlerNoAdminConsole(t *testing.T) {
srv := connectsrv.NewServer(connectsrv.Deps{})
front := httptest.NewServer(srv.HTTPHandler())
defer front.Close()
resp, err := http.Get(front.URL + "/_gm/")
if err != nil {
t.Fatal(err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusNotFound {
t.Fatalf("/_gm status = %d, want 404 (no admin proxy)", resp.StatusCode)
}
}