test get to /

This commit is contained in:
Bel LaPointe
2024-02-20 08:09:13 -07:00
parent ec8d451df8
commit 324d4f430e
2 changed files with 17 additions and 1 deletions

View File

@@ -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
}

View File

@@ -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("<html>")) {
t.Errorf("%s", w.Body.Bytes())
}
})
}