proxy-pool/cmd/proxy-checker/main_test.go
youfak 2bdc1ebda3
Some checks are pending
ci / proto (push) Waiting to run
ci / test (ubuntu-latest) (push) Waiting to run
ci / test (windows-latest) (push) Waiting to run
ci / race (push) Waiting to run
ci / integration (push) Waiting to run
feat: add checker task executor
2026-07-31 21:12:32 +08:00

36 lines
1.3 KiB
Go

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