@@ -18,12 +18,15 @@ package canary
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"testing"
22
23
23
24
"github.com/stretchr/testify/assert"
24
25
"github.com/stretchr/testify/require"
25
26
26
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
+ "k8s.io/apimachinery/pkg/runtime"
29
+ k8sTesting "k8s.io/client-go/testing"
27
30
)
28
31
29
32
func TestConfigIsDisabled (t * testing.T ) {
@@ -303,3 +306,29 @@ func TestConfigTracker_Secrets(t *testing.T) {
303
306
assert .True (t , originalVolPresent , "Volume for original secret with disabled tracking should be present" )
304
307
})
305
308
}
309
+
310
+ func TestConfigTracker_HasConfigChanged_ShouldReturnErrorWhenAPIServerIsDown (t * testing.T ) {
311
+ t .Run ("secret" , func (t * testing.T ) {
312
+ dc := deploymentConfigs {name : "podinfo" , label : "name" , labelValue : "podinfo" }
313
+ mocks , kubeClient := newCustomizableFixture (dc )
314
+
315
+ kubeClient .PrependReactor ("get" , "secrets" , func (action k8sTesting.Action ) (bool , runtime.Object , error ) {
316
+ return true , nil , errors .New ("server error" )
317
+ })
318
+
319
+ _ , err := mocks .controller .configTracker .HasConfigChanged (mocks .canary )
320
+ assert .Error (t , err )
321
+ })
322
+
323
+ t .Run ("configmap" , func (t * testing.T ) {
324
+ dc := deploymentConfigs {name : "podinfo" , label : "name" , labelValue : "podinfo" }
325
+ mocks , kubeClient := newCustomizableFixture (dc )
326
+
327
+ kubeClient .PrependReactor ("get" , "configmaps" , func (action k8sTesting.Action ) (bool , runtime.Object , error ) {
328
+ return true , nil , errors .New ("server error" )
329
+ })
330
+
331
+ _ , err := mocks .controller .configTracker .HasConfigChanged (mocks .canary )
332
+ assert .Error (t , err )
333
+ })
334
+ }
0 commit comments