Files
archie/internal/daemon/statestore_target_test.go
sam e7d3ed72e4 fix(container): task containers run on their own sandbox network behind the egress relay (#1867)
Each task container now gets an internal bridge with no host address,
shared only with the egress relay. NATS, the State Store and the model
proxy are reached through the relay's ports; a loopback State Store is
forwarded to the host gateway. The network is removed with the task, and
boot sweeps any a previous daemon left. The per-task State Store relay on
the host bridge is gone.
2026-11-14 00:14:21 +11:00

41 lines
1.6 KiB
Go

package daemon
import "testing"
// TestRelayStateStoreTarget guards where the egress relay sends task State
// Store traffic: a loopback target is reached at the host gateway on the same
// port, since loopback inside the relay names the relay itself, and any other
// target passes through untouched.
func TestRelayStateStoreTarget(t *testing.T) {
t.Parallel()
cases := []struct {
name string
target string
gateway string
want string
wantErr bool
}{
{name: "loopback ipv4", target: "127.0.0.1:9090", gateway: "172.17.0.1", want: "172.17.0.1:9090"},
{name: "loopback ipv6", target: "[::1]:9090", gateway: "172.17.0.1", want: "172.17.0.1:9090"},
{name: "localhost", target: "localhost:9090", gateway: "172.17.0.1", want: "172.17.0.1:9090"},
{name: "grpc scheme form", target: "dns:///127.0.0.1:9090", gateway: "172.17.0.1", want: "172.17.0.1:9090"},
{name: "host address", target: "10.0.0.5:9090", gateway: "172.17.0.1", want: "10.0.0.5:9090"},
{name: "service name", target: "dns:///state-store:9090", want: "state-store:9090"},
{name: "loopback without a gateway", target: "127.0.0.1:9090", wantErr: true},
{name: "unset", target: "", wantErr: true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
got, err := RelayStateStoreTarget(tc.target, tc.gateway)
if (err != nil) != tc.wantErr {
t.Fatalf("RelayStateStoreTarget(%q, %q) error = %v, want error %t", tc.target, tc.gateway, err, tc.wantErr)
}
if got != tc.want {
t.Fatalf("RelayStateStoreTarget(%q, %q) = %q, want %q", tc.target, tc.gateway, got, tc.want)
}
})
}
}