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) } }) } }