MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestInitManager

Function TestInitManager

cmd/postgres-operator/main_test.go:17–130  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestInitManager(t *testing.T) {
18 ctx := context.Background()
19
20 t.Run("Defaults", func(t *testing.T) {
21 options, err := initManager(ctx)
22 assert.NilError(t, err)
23
24 if assert.Check(t, options.Cache.SyncPeriod != nil) {
25 assert.Equal(t, *options.Cache.SyncPeriod, time.Hour)
26 }
27
28 assert.Equal(t, len(options.Metrics.TLSOpts), 1)
29 assert.Assert(t, options.Metrics.BindAddress == ":8443")
30 assert.Assert(t, options.Metrics.SecureServing == true)
31 assert.Assert(t, options.Metrics.FilterProvider != nil)
32
33 assert.Assert(t, options.HealthProbeBindAddress == ":8081")
34
35 assert.DeepEqual(t, options.Controller.GroupKindConcurrency,
36 map[string]int{
37 "PostgresCluster.postgres-operator.crunchydata.com": 2,
38 })
39
40 assert.Assert(t, options.Cache.DefaultNamespaces == nil)
41 assert.Assert(t, options.LeaderElection == false)
42
43 {
44 options.Cache.SyncPeriod = nil
45 options.Controller.GroupKindConcurrency = nil
46 options.HealthProbeBindAddress = ""
47 options.Metrics.TLSOpts = nil
48 options.Metrics.BindAddress = ""
49 options.Metrics.SecureServing = false
50 options.Metrics.FilterProvider = nil
51
52 assert.Assert(t, reflect.ValueOf(options).IsZero(),
53 "expected remaining fields to be unset:\n%+v", options)
54 }
55 })
56
57 t.Run("PGO_CONTROLLER_LEASE_NAME", func(t *testing.T) {
58 t.Setenv("PGO_NAMESPACE", "test-namespace")
59
60 t.Run("Invalid", func(t *testing.T) {
61 t.Setenv("PGO_CONTROLLER_LEASE_NAME", "INVALID_NAME")
62
63 options, err := initManager(ctx)
64 assert.ErrorContains(t, err, "PGO_CONTROLLER_LEASE_NAME")
65 assert.ErrorContains(t, err, "invalid")
66
67 assert.Assert(t, options.LeaderElection == false)
68 assert.Equal(t, options.LeaderElectionNamespace, "")
69 })
70
71 t.Run("Valid", func(t *testing.T) {
72 t.Setenv("PGO_CONTROLLER_LEASE_NAME", "valid-name")
73
74 options, err := initManager(ctx)

Callers

nothing calls this directly

Calls 3

initManagerFunction · 0.85
LenMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected