1
1
package k8s
2
2
3
3
import (
4
+ "errors"
4
5
"testing"
5
6
6
7
v1 "k8s.io/api/core/v1"
@@ -158,9 +159,10 @@ func TestHasServicePortChanges(t *testing.T) {
158
159
159
160
func TestAreResourcesDifferent (t * testing.T ) {
160
161
tests := []struct {
161
- oldR , newR * unstructured.Unstructured
162
- expected , expectErr bool
163
- msg string
162
+ oldR , newR * unstructured.Unstructured
163
+ expected bool
164
+ expectErr error
165
+ msg string
164
166
}{
165
167
{
166
168
oldR : & unstructured.Unstructured {
@@ -174,7 +176,7 @@ func TestAreResourcesDifferent(t *testing.T) {
174
176
},
175
177
},
176
178
expected : false ,
177
- expectErr : true ,
179
+ expectErr : errors . New ( `.spec accessor error: true is of the type bool, expected map[string]interface{}` ) ,
178
180
msg : "invalid old resource" ,
179
181
},
180
182
{
@@ -189,7 +191,7 @@ func TestAreResourcesDifferent(t *testing.T) {
189
191
},
190
192
},
191
193
expected : false ,
192
- expectErr : true ,
194
+ expectErr : errors . New ( `.spec accessor error: true is of the type bool, expected map[string]interface{}` ) ,
193
195
msg : "invalid new resource" ,
194
196
},
195
197
{
@@ -202,7 +204,7 @@ func TestAreResourcesDifferent(t *testing.T) {
202
204
Object : map [string ]interface {}{},
203
205
},
204
206
expected : false ,
205
- expectErr : true ,
207
+ expectErr : errors . New ( `Error, spec has unexpected format` ) ,
206
208
msg : "new resource with missing spec" ,
207
209
},
208
210
{
@@ -221,7 +223,7 @@ func TestAreResourcesDifferent(t *testing.T) {
221
223
},
222
224
},
223
225
expected : false ,
224
- expectErr : false ,
226
+ expectErr : nil ,
225
227
msg : "equal resources" ,
226
228
},
227
229
{
@@ -240,7 +242,7 @@ func TestAreResourcesDifferent(t *testing.T) {
240
242
},
241
243
},
242
244
expected : true ,
243
- expectErr : false ,
245
+ expectErr : nil ,
244
246
msg : "not equal resources" ,
245
247
},
246
248
{
@@ -255,7 +257,7 @@ func TestAreResourcesDifferent(t *testing.T) {
255
257
},
256
258
},
257
259
expected : true ,
258
- expectErr : false ,
260
+ expectErr : nil ,
259
261
msg : "not equal resources with with first resource missing spec" ,
260
262
},
261
263
}
@@ -265,10 +267,14 @@ func TestAreResourcesDifferent(t *testing.T) {
265
267
if result != test .expected {
266
268
t .Errorf ("areResourcesDifferent() returned %v but expected %v for the case of %s" , result , test .expected , test .msg )
267
269
}
268
- if test .expectErr && err == nil {
269
- t .Errorf ("areResourcesDifferent() returned no error for the case of %s" , test .msg )
270
+ if test .expectErr != nil {
271
+ if err == nil {
272
+ t .Errorf ("areResourcesDifferent() returned no error for the case of %s" , test .msg )
273
+ } else if test .expectErr .Error () != err .Error () {
274
+ t .Errorf ("areResourcesDifferent() returned an unexpected error '%v' for the case of %s" , err , test .msg )
275
+ }
270
276
}
271
- if ! test .expectErr && err != nil {
277
+ if test .expectErr == nil && err != nil {
272
278
t .Errorf ("areResourcesDifferent() returned unexpected error %v for the case of %s" , err , test .msg )
273
279
}
274
280
}
0 commit comments