wipp
This commit is contained in:
27
cmd/server/main_test.go
Normal file
27
cmd/server/main_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRunHTTP(t *testing.T) {
|
||||
cfg := Config{}
|
||||
|
||||
h := cfg.NewHandler()
|
||||
|
||||
t.Run("requires auth", func(t *testing.T) {
|
||||
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
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 != 401 {
|
||||
t.Error(w.Code)
|
||||
}
|
||||
if w.Header().Get("WWW-Authenticate") == "" {
|
||||
t.Errorf("expected WWW-Authenticate header but got %+v", w.Header())
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user