...
1 package controller
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 "k8s.io/client-go/rest"
8 "sigs.k8s.io/controller-runtime/pkg/webhook"
9 )
10
11 func TestProcessOptions_Defaults(t *testing.T) {
12 _, opts := ProcessOptions(WithCfg(&rest.Config{}))
13 assert.Equal(t, defaultMetricsBindAddress, opts.Metrics.BindAddress,
14 "metrics bind address should be set to the default when not provided")
15 assert.Equal(t, defaultLeaderElection, opts.LeaderElection,
16 "leader election should be set to the default value when not provided")
17 }
18
19 func TestProcessOptions_WithCfg(t *testing.T) {
20 input := &rest.Config{}
21 cfg, _ := ProcessOptions(WithCfg(input))
22 assert.Same(t, input, cfg, "should return the provided config")
23 }
24
25 func TestProcessOptions_WithLeaderElection(t *testing.T) {
26 _, opts := ProcessOptions(WithLeaderElection(), WithCfg(&rest.Config{}))
27 assert.True(t, opts.LeaderElection,
28 "should return options with leader election enabled")
29 }
30
31 func TestProcessOptions_WithPort(t *testing.T) {
32 _, opts := ProcessOptions(WithPort(8080), WithCfg(&rest.Config{}))
33 assert.Equal(t, opts.WebhookServer.(*webhook.DefaultServer).Options.Port, 8080, "webhook port config invalid")
34 }
35
36 func TestProcessOptions_WithCertDir(t *testing.T) {
37 _, opts := ProcessOptions(WithCertDir("/var/cert"), WithCfg(&rest.Config{}))
38 assert.Equal(t, opts.WebhookServer.(*webhook.DefaultServer).Options.CertDir, "/var/cert", "webhook cert dir config invalid")
39 }
40
View as plain text