Files
zero-scale-platform/internal/proxy/proxy_test.go
claude cd30ee48ba Share app naming between CLI and gateway; map every hostname to one app
- internal/appname: one naming rule (first label, lowercased, [a-z0-9] only)
- internal/registry: host -> app cache built from zero-scale-app ConfigMaps
  (hosts key), with direct and legacy-name fallbacks and a 10s TTL
- gateway: units, binaries and config keyed by the app's canonical host, so
  secondary hostnames share one process and one config
- reaper reads app config from the registry instead of the API every tick
- zero-scale-ctl writes a hosts key and uses the shared naming rule
2026-10-27 06:44:55 -04:00

41 lines
1.2 KiB
Go

package proxy
import (
"os"
"path/filepath"
"testing"
"git.fairfaxmedia.net/open-cream-cheese/zero-scale-platform/internal/config"
)
func TestResolveBinary(t *testing.T) {
dir := t.TempDir()
touch := func(name string) {
if err := os.WriteFile(filepath.Join(dir, name), []byte("x"), 0755); err != nil {
t.Fatal(err)
}
}
touch("fdm.ffxm.cc")
touch("bdash2.kube.example.net")
g := New(&config.Config{AppsDir: dir}, nil)
cases := []struct{ host, request, want string }{
{"fdm.ffxm.cc", "fleet.example.com", "fdm.ffxm.cc"}, // secondary host uses canonical binary
{"other.example.com", "fdm.ffxm.cc", "fdm.ffxm.cc"}, // falls back to the request host
{"bdash2.example.com", "bdash2.example.com", "bdash2.kube.example.net"}, // legacy short-name match
{"missing.example.com", "missing.example.com", ""},
}
for _, c := range cases {
got := g.resolveBinary(c.host, c.request)
if c.want == "" {
if got != "" {
t.Errorf("resolveBinary(%q, %q) = %q, want none", c.host, c.request, got)
}
continue
}
if got != filepath.Join(dir, c.want) {
t.Errorf("resolveBinary(%q, %q) = %q, want %q", c.host, c.request, got, c.want)
}
}
}