package main import ( "context" "io" "strings" "testing" "proxy-pool/internal/gateway/bootstrap" ) func TestExecutePassesExplicitGatewayIdentity(t *testing.T) { t.Parallel() var captured bootstrap.Options status := execute(context.Background(), []string{ "-config", "gateway.yaml", "-control-plane", "127.0.0.1:8443", "-cluster-id", "cluster-a", "-worker-id", "worker-a", "-instance-id", "instance-a", "-zone", "zone-a", }, func(string) string { return "" }, func(_ context.Context, options bootstrap.Options) error { captured = options return nil }, io.Discard) if status != 0 { t.Fatalf("execute() status = %d, want 0", status) } if captured.ConfigPath != "gateway.yaml" || captured.ControlPlaneAddress != "127.0.0.1:8443" || captured.ClusterID != "cluster-a" || captured.WorkerID != "worker-a" || captured.InstanceID != "instance-a" || captured.Zone != "zone-a" { t.Fatalf("bootstrap options = %+v", captured) } } func TestExecuteReadsGatewayOptionsFromEnvironment(t *testing.T) { t.Parallel() values := map[string]string{ configEnvironment: "gateway.yaml", controlPlaneAddressEnvironment: "127.0.0.1:8443", clusterIDEnvironment: "cluster-a", workerIDEnvironment: "worker-a", instanceIDEnvironment: "instance-a", zoneEnvironment: "zone-a", } var captured bootstrap.Options status := execute(context.Background(), nil, func(name string) string { return values[name] }, func(_ context.Context, options bootstrap.Options) error { captured = options return nil }, io.Discard) if status != 0 || captured.WorkerID != "worker-a" || captured.ControlPlaneAddress != "127.0.0.1:8443" { t.Fatalf("execute() = (%d, %+v)", status, captured) } } func TestExecutePassesAutoGatewayIdentityFromEnvironment(t *testing.T) { captured := bootstrap.Options{} values := map[string]string{ configEnvironment: "gateway.yaml", controlPlaneAddressEnvironment: "127.0.0.1:8443", clusterIDEnvironment: "cluster-a", zoneEnvironment: "zone-a", autoIdentityEnvironment: "true", } code := execute(context.Background(), nil, func(name string) string { return values[name] }, func(_ context.Context, options bootstrap.Options) error { captured = options return nil }, io.Discard) if code != 0 || !captured.AutoIdentity || captured.WorkerID != "" || captured.InstanceID != "" { t.Fatalf("execute(auto identity) = (%d, %+v)", code, captured) } } func TestExecuteRejectsIncompleteGatewayOptions(t *testing.T) { t.Parallel() var output strings.Builder status := execute(context.Background(), []string{"-config", "gateway.yaml"}, func(string) string { return "" }, nil, &output) if status != 2 || !strings.Contains(output.String(), controlPlaneAddressEnvironment) { t.Fatalf("execute() = (%d, %q), want usage error naming missing environment", status, output.String()) } }