package controller import ( "testing" "github.com/stretchr/testify/assert" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/webhook" ) func TestProcessOptions_Defaults(t *testing.T) { _, opts := ProcessOptions(WithCfg(&rest.Config{})) assert.Equal(t, defaultMetricsBindAddress, opts.Metrics.BindAddress, "metrics bind address should be set to the default when not provided") assert.Equal(t, defaultLeaderElection, opts.LeaderElection, "leader election should be set to the default value when not provided") } func TestProcessOptions_WithCfg(t *testing.T) { input := &rest.Config{} cfg, _ := ProcessOptions(WithCfg(input)) assert.Same(t, input, cfg, "should return the provided config") } func TestProcessOptions_WithLeaderElection(t *testing.T) { _, opts := ProcessOptions(WithLeaderElection(), WithCfg(&rest.Config{})) assert.True(t, opts.LeaderElection, "should return options with leader election enabled") } func TestProcessOptions_WithPort(t *testing.T) { _, opts := ProcessOptions(WithPort(8080), WithCfg(&rest.Config{})) assert.Equal(t, opts.WebhookServer.(*webhook.DefaultServer).Options.Port, 8080, "webhook port config invalid") } func TestProcessOptions_WithCertDir(t *testing.T) { _, opts := ProcessOptions(WithCertDir("/var/cert"), WithCfg(&rest.Config{})) assert.Equal(t, opts.WebhookServer.(*webhook.DefaultServer).Options.CertDir, "/var/cert", "webhook cert dir config invalid") }