Files
vibeproxy/internal/runtime/store_test.go
T
owenandClaude Sonnet 5 ba1f7c4c03 Initial vibeproxy implementation
Self-contained HTTP/HTTPS/TCP/UDP reverse proxy manager written in Go,
with SQLite storage, a Bootstrap 5 admin UI (Go templates, no JS
framework), and a REST API under /api/v1.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QTXFrNP1imCW7jtfL5SZrw
2026-08-17 10:28:59 -05:00

47 lines
1.2 KiB
Go

package runtime
import (
"net"
"testing"
"github.com/owen/vibeproxy/internal/models"
)
func TestSnapshotLookupHost(t *testing.T) {
snap := &Snapshot{
HostsByDomain: map[string]*ProxyHostRuntime{
"example.com": {Model: models.ProxyHost{Name: "example"}},
},
}
if rt := snap.LookupHost("Example.com:8443"); rt == nil || rt.Model.Name != "example" {
t.Fatalf("expected case-insensitive, port-stripped lookup to match, got %+v", rt)
}
if rt := snap.LookupHost("other.com"); rt != nil {
t.Fatalf("expected no match for unknown host, got %+v", rt)
}
}
func TestSnapshotTrustedProxy(t *testing.T) {
_, cidr, err := net.ParseCIDR("10.0.0.0/8")
if err != nil {
t.Fatal(err)
}
snap := &Snapshot{TrustedProxies: []*net.IPNet{cidr}}
if !snap.IsTrustedProxy(net.ParseIP("10.1.2.3")) {
t.Fatal("expected 10.1.2.3 to be trusted")
}
if snap.IsTrustedProxy(net.ParseIP("8.8.8.8")) {
t.Fatal("expected 8.8.8.8 not to be trusted")
}
}
func TestSettingsFromMapDefaults(t *testing.T) {
s := settingsFromMap(map[string]string{})
if s.LogRetentionDays != 30 {
t.Fatalf("expected default retention 30, got %d", s.LogRetentionDays)
}
if s.AdminUsername != "admin" {
t.Fatalf("expected default admin username, got %q", s.AdminUsername)
}
}