36 lines
1.3 KiB
Go
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)
|
|
}
|
|
}
|