test get to /
This commit is contained in:
@@ -134,7 +134,7 @@ var public = func() http.FileSystem {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
func (h Handler) handle(session Session, w http.ResponseWriter, r *http.Request) error {
|
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)
|
http.FileServer(public).ServeHTTP(w, r)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -24,4 +25,19 @@ func TestRunHTTP(t *testing.T) {
|
|||||||
t.Errorf("expected WWW-Authenticate header but got %+v", w.Header())
|
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())
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user