impl home.

This commit is contained in:
Bel LaPointe
2026-01-31 16:18:25 -07:00
parent 057a0ab341
commit 7d3da593ca
2 changed files with 72 additions and 3 deletions

View File

@@ -38,20 +38,39 @@ func TestServerStart(t *testing.T) {
}
func mockServer() *Server {
s := _mockServer()
portServer := httptest.NewServer(nil)
port := strings.Split(portServer.URL, ":")[2]
s.addr = ":" + strings.Split(portServer.URL, ":")[2]
portServer.Close()
return s
}
func _mockServer() *Server {
s := &Server{
db: storage.NewMap(),
addr: ":" + port,
limiter: rate.NewLimiter(rate.Limit(50), 50),
}
if err := s.Routes(); err != nil {
panic(fmt.Sprintf("cannot initiate server routes; %v", err))
}
if err := s.Route("test", config.Proxy{To: "http://icanhazip.com"}); err != nil {
panic(err.Error())
}
return s
}
func TestServerHome(t *testing.T) {
s := _mockServer()
r := httptest.NewRequest(http.MethodGet, "https://home.int.bel.blue", nil)
w := httptest.NewRecorder()
s.Home(w, r)
if w.Code != http.StatusOK {
t.Fatalf("(%d) %s", w.Code, w.Body.Bytes())
}
t.Logf("%s", w.Body.Bytes())
}
func TestServerRoute(t *testing.T) {
server := mockServer()
p := config.Proxy{