@@ -21,24 +21,16 @@ func TestUpdateConfig(t *testing.T) {
21
21
t .Parallel ()
22
22
23
23
tests := []struct {
24
- name string
25
- configApplied bool
26
- expErr bool
24
+ name string
25
+ expErr bool
27
26
}{
28
27
{
29
- name : "success" ,
30
- configApplied : true ,
31
- expErr : false ,
28
+ name : "success" ,
29
+ expErr : false ,
32
30
},
33
31
{
34
- name : "error returned from agent" ,
35
- configApplied : true ,
36
- expErr : true ,
37
- },
38
- {
39
- name : "configuration not applied" ,
40
- configApplied : false ,
41
- expErr : false ,
32
+ name : "error returned from agent" ,
33
+ expErr : true ,
42
34
},
43
35
}
44
36
@@ -48,7 +40,7 @@ func TestUpdateConfig(t *testing.T) {
48
40
g := NewWithT (t )
49
41
50
42
fakeBroadcaster := & broadcastfakes.FakeBroadcaster {}
51
- fakeBroadcaster .SendReturns (test . configApplied )
43
+ fakeBroadcaster .SendReturns (true )
52
44
53
45
plus := false
54
46
updater := NewNginxUpdater (logr .Discard (), fake .NewFakeClient (), & status.Queue {}, nil , plus )
@@ -70,9 +62,9 @@ func TestUpdateConfig(t *testing.T) {
70
62
deployment .SetPodErrorStatus ("pod1" , testErr )
71
63
}
72
64
73
- applied := updater .UpdateConfig (deployment , []File {file })
65
+ updater .UpdateConfig (deployment , []File {file })
74
66
75
- g .Expect (applied ) .To (Equal (test . configApplied ))
67
+ g .Expect (fakeBroadcaster . SendCallCount ()) .To (Equal (1 ))
76
68
g .Expect (deployment .GetFile (file .Meta .Name , file .Meta .Hash )).To (Equal (file .Contents ))
77
69
78
70
if test .expErr {
@@ -114,10 +106,9 @@ func TestUpdateConfig_NoChange(t *testing.T) {
114
106
deployment .SetFiles ([]File {file })
115
107
116
108
// Call UpdateConfig with the same files
117
- applied := updater .UpdateConfig (deployment , []File {file })
109
+ updater .UpdateConfig (deployment , []File {file })
118
110
119
111
// Verify that no new configuration was sent
120
- g .Expect (applied ).To (BeFalse ())
121
112
g .Expect (fakeBroadcaster .SendCallCount ()).To (Equal (0 ))
122
113
}
123
114
@@ -128,43 +119,31 @@ func TestUpdateUpstreamServers(t *testing.T) {
128
119
name string
129
120
buildUpstreams bool
130
121
plus bool
131
- configApplied bool
132
122
expErr bool
133
123
}{
134
124
{
135
125
name : "success" ,
136
126
plus : true ,
137
127
buildUpstreams : true ,
138
- configApplied : true ,
139
128
expErr : false ,
140
129
},
141
130
{
142
131
name : "no upstreams to apply" ,
143
132
plus : true ,
144
133
buildUpstreams : false ,
145
- configApplied : false ,
146
134
expErr : false ,
147
135
},
148
136
{
149
- name : "not running nginx plus" ,
150
- plus : false ,
151
- configApplied : false ,
152
- expErr : false ,
137
+ name : "not running nginx plus" ,
138
+ plus : false ,
139
+ expErr : false ,
153
140
},
154
141
{
155
142
name : "error returned from agent" ,
156
143
plus : true ,
157
144
buildUpstreams : true ,
158
- configApplied : true ,
159
145
expErr : true ,
160
146
},
161
- {
162
- name : "configuration not applied" ,
163
- plus : true ,
164
- buildUpstreams : true ,
165
- configApplied : false ,
166
- expErr : false ,
167
- },
168
147
}
169
148
170
149
for _ , test := range tests {
@@ -173,7 +152,6 @@ func TestUpdateUpstreamServers(t *testing.T) {
173
152
g := NewWithT (t )
174
153
175
154
fakeBroadcaster := & broadcastfakes.FakeBroadcaster {}
176
- fakeBroadcaster .SendReturns (test .configApplied )
177
155
178
156
updater := NewNginxUpdater (logr .Discard (), fake .NewFakeClient (), & status.Queue {}, nil , test .plus )
179
157
updater .retryTimeout = 0
@@ -215,8 +193,7 @@ func TestUpdateUpstreamServers(t *testing.T) {
215
193
}
216
194
}
217
195
218
- applied := updater .UpdateUpstreamServers (deployment , conf )
219
- g .Expect (applied ).To (Equal (test .configApplied ))
196
+ updater .UpdateUpstreamServers (deployment , conf )
220
197
221
198
expActions := make ([]* pb.NGINXPlusAction , 0 )
222
199
if test .buildUpstreams {
@@ -254,8 +231,10 @@ func TestUpdateUpstreamServers(t *testing.T) {
254
231
255
232
if ! test .plus {
256
233
g .Expect (deployment .GetNGINXPlusActions ()).To (BeNil ())
234
+ g .Expect (fakeBroadcaster .SendCallCount ()).To (Equal (0 ))
257
235
} else if test .buildUpstreams {
258
236
g .Expect (deployment .GetNGINXPlusActions ()).To (Equal (expActions ))
237
+ g .Expect (fakeBroadcaster .SendCallCount ()).To (Equal (2 ))
259
238
}
260
239
261
240
if test .expErr {
@@ -347,10 +326,9 @@ func TestUpdateUpstreamServers_NoChange(t *testing.T) {
347
326
deployment .SetNGINXPlusActions (initialActions )
348
327
349
328
// Call UpdateUpstreamServers with the same configuration
350
- applied := updater .UpdateUpstreamServers (deployment , conf )
329
+ updater .UpdateUpstreamServers (deployment , conf )
351
330
352
331
// Verify that no new actions were sent
353
- g .Expect (applied ).To (BeFalse ())
354
332
g .Expect (fakeBroadcaster .SendCallCount ()).To (Equal (0 ))
355
333
}
356
334
0 commit comments