package main import ( "context" "io" "testing" controlplanev1 "proxy-pool/gen/controlplane/v1" "proxy-pool/internal/checker/bootstrap" ) func TestExecuteUsesFlagsAndPassesCheckerIdentity(t *testing.T) { var received bootstrap.Options code := execute(context.Background(), []string{ "-config", "config.yaml", "-control-plane", "127.0.0.1:8443", "-checker-id", "checker-a", "-instance-id", "instance-a", "-max-in-flight", "2", "-levels", "basic,target", }, nil, func(_ context.Context, options bootstrap.Options) error { received = options return nil }, io.Discard) if code != 0 || received.CheckerID != "checker-a" || received.MaxInFlight != 2 || len(received.SupportedLevels) != 2 || received.SupportedLevels[1] != controlplanev1.CheckLevel_CHECK_LEVEL_TARGET { t.Fatalf("execute() code=%d options=%+v", code, received) } } func TestExecutePassesAutoCheckerIdentityFromEnvironment(t *testing.T) { received := bootstrap.Options{} values := map[string]string{ configEnvironment: "checker.yaml", controlPlaneAddressEnvironment: "127.0.0.1:8443", maxInFlightEnvironment: "2", autoIdentityEnvironment: "true", } code := execute(context.Background(), nil, func(name string) string { return values[name] }, func(_ context.Context, options bootstrap.Options) error { received = options return nil }, io.Discard) if code != 0 || !received.AutoIdentity || received.CheckerID != "" || received.InstanceID != "" { t.Fatalf("execute(auto identity) = (%d, %+v)", code, received) } } func TestExecuteRejectsInvalidLevelSet(t *testing.T) { code := execute(context.Background(), []string{ "-config", "config.yaml", "-control-plane", "127.0.0.1:8443", "-checker-id", "checker-a", "-instance-id", "instance-a", "-max-in-flight", "2", "-levels", "basic,basic", }, nil, func(context.Context, bootstrap.Options) error { return nil }, io.Discard) if code != 2 { t.Fatalf("execute(invalid levels) = %d, want 2", code) } }