From 324d4f430e16101198fddfb63c0e322f012e20a3 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Tue, 20 Feb 2024 08:09:13 -0700 Subject: [PATCH] test get to / --- cmd/server/main.go | 2 +- cmd/server/main_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index c9f3a3b..9be3556 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -134,7 +134,7 @@ var public = func() http.FileSystem { }() func (h Handler) handle(session Session, w http.ResponseWriter, r *http.Request) error { - if !strings.HasPrefix(r.URL.Path, "/api") { + if !strings.HasPrefix(r.URL.Path, "/api/") { http.FileServer(public).ServeHTTP(w, r) return nil } diff --git a/cmd/server/main_test.go b/cmd/server/main_test.go index 2187353..6ec8ee0 100644 --- a/cmd/server/main_test.go +++ b/cmd/server/main_test.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "net/http" "net/http/httptest" "testing" @@ -24,4 +25,19 @@ func TestRunHTTP(t *testing.T) { t.Errorf("expected WWW-Authenticate header but got %+v", w.Header()) } }) + + t.Run("/", func(t *testing.T) { + r := httptest.NewRequest(http.MethodGet, "/", nil) + r.SetBasicAuth("b", "b") + w := httptest.NewRecorder() + t.Logf("%s %s", r.Method, r.URL) + h.ServeHTTP(w, r) + t.Logf("(%d) %s", w.Code, w.Body.Bytes()) + if w.Code != http.StatusOK { + t.Error(w.Code) + } + if !bytes.Contains(w.Body.Bytes(), []byte("")) { + t.Errorf("%s", w.Body.Bytes()) + } + }) }