5
5
package main
6
6
7
7
import (
8
+ "context"
8
9
"reflect"
9
10
"testing"
10
11
"time"
@@ -14,8 +15,9 @@ import (
14
15
)
15
16
16
17
func TestInitManager (t * testing.T ) {
18
+ ctx := context .Background ()
17
19
t .Run ("Defaults" , func (t * testing.T ) {
18
- options , err := initManager ()
20
+ options , err := initManager (ctx )
19
21
assert .NilError (t , err )
20
22
21
23
if assert .Check (t , options .Cache .SyncPeriod != nil ) {
@@ -30,12 +32,14 @@ func TestInitManager(t *testing.T) {
30
32
})
31
33
32
34
assert .Assert (t , options .Cache .DefaultNamespaces == nil )
33
- assert .Assert (t , options .LeaderElection == false )
35
+ assert .Assert (t , options .LeaderElection == true )
34
36
35
37
{
36
38
options .Cache .SyncPeriod = nil
37
39
options .Controller .GroupKindConcurrency = nil
38
40
options .HealthProbeBindAddress = ""
41
+ options .LeaderElection = false
42
+ options .LeaderElectionID = ""
39
43
40
44
assert .Assert (t , reflect .ValueOf (options ).IsZero (),
41
45
"expected remaining fields to be unset:\n %+v" , options )
@@ -48,7 +52,7 @@ func TestInitManager(t *testing.T) {
48
52
t .Run ("Invalid" , func (t * testing.T ) {
49
53
t .Setenv ("PGO_CONTROLLER_LEASE_NAME" , "INVALID_NAME" )
50
54
51
- options , err := initManager ()
55
+ options , err := initManager (ctx )
52
56
assert .ErrorContains (t , err , "PGO_CONTROLLER_LEASE_NAME" )
53
57
assert .ErrorContains (t , err , "invalid" )
54
58
@@ -59,7 +63,7 @@ func TestInitManager(t *testing.T) {
59
63
t .Run ("Valid" , func (t * testing.T ) {
60
64
t .Setenv ("PGO_CONTROLLER_LEASE_NAME" , "valid-name" )
61
65
62
- options , err := initManager ()
66
+ options , err := initManager (ctx )
63
67
assert .NilError (t , err )
64
68
assert .Assert (t , options .LeaderElection == true )
65
69
assert .Equal (t , options .LeaderElectionNamespace , "test-namespace" )
@@ -70,7 +74,7 @@ func TestInitManager(t *testing.T) {
70
74
t .Run ("PGO_TARGET_NAMESPACE" , func (t * testing.T ) {
71
75
t .Setenv ("PGO_TARGET_NAMESPACE" , "some-such" )
72
76
73
- options , err := initManager ()
77
+ options , err := initManager (ctx )
74
78
assert .NilError (t , err )
75
79
assert .Assert (t , cmp .Len (options .Cache .DefaultNamespaces , 1 ),
76
80
"expected only one configured namespace" )
@@ -81,7 +85,7 @@ func TestInitManager(t *testing.T) {
81
85
t .Run ("PGO_TARGET_NAMESPACES" , func (t * testing.T ) {
82
86
t .Setenv ("PGO_TARGET_NAMESPACES" , "some-such,another-one" )
83
87
84
- options , err := initManager ()
88
+ options , err := initManager (ctx )
85
89
assert .NilError (t , err )
86
90
assert .Assert (t , cmp .Len (options .Cache .DefaultNamespaces , 2 ),
87
91
"expect two configured namespaces" )
@@ -95,7 +99,7 @@ func TestInitManager(t *testing.T) {
95
99
for _ , v := range []string {"-3" , "0" , "3.14" } {
96
100
t .Setenv ("PGO_WORKERS" , v )
97
101
98
- options , err := initManager ()
102
+ options , err := initManager (ctx )
99
103
assert .NilError (t , err )
100
104
assert .DeepEqual (t , options .Controller .GroupKindConcurrency ,
101
105
map [string ]int {
@@ -107,7 +111,7 @@ func TestInitManager(t *testing.T) {
107
111
t .Run ("Valid" , func (t * testing.T ) {
108
112
t .Setenv ("PGO_WORKERS" , "19" )
109
113
110
- options , err := initManager ()
114
+ options , err := initManager (ctx )
111
115
assert .NilError (t , err )
112
116
assert .DeepEqual (t , options .Controller .GroupKindConcurrency ,
113
117
map [string ]int {
0 commit comments