37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizeDomain(t *testing.T) {
|
|
cases := map[string]string{"example.com": "example.com", "https://WWW.Example.com/a": "www.example.com", "example.com/": "example.com"}
|
|
for in, want := range cases {
|
|
got, err := normalizeDomain(in)
|
|
if err != nil || got != want {
|
|
t.Fatalf("%q: got %q, %v", in, got, err)
|
|
}
|
|
}
|
|
for _, in := range []string{"localhost", "127.0.0.1", "bad_domain.com", "-bad.com"} {
|
|
if _, err := normalizeDomain(in); err == nil {
|
|
t.Fatalf("expected %q invalid", in)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestWebAssetRoutes(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/web/", http.StripPrefix("/web", staticHandler()))
|
|
mux.Handle("/", staticHandler())
|
|
|
|
for _, path := range []string{"/", "/web/app.js", "/web/style.css"} {
|
|
recorder := httptest.NewRecorder()
|
|
mux.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, path, nil))
|
|
if recorder.Code != http.StatusOK {
|
|
t.Errorf("GET %s returned %d, want 200", path, recorder.Code)
|
|
}
|
|
}
|
|
}
|