From 429720ee9428488392f3b0a36aa3638d92c60fc9 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Wed, 3 Apr 2019 13:38:41 -0400 Subject: [PATCH] Fix unit test panic --- .../cloudprovider/observe_cloudprovider.go | 15 ++++++++++----- .../cloudprovider/observe_cloudprovider_test.go | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pkg/operator/configobservation/cloudprovider/observe_cloudprovider.go b/pkg/operator/configobservation/cloudprovider/observe_cloudprovider.go index 03369b928..a3a41fc3d 100644 --- a/pkg/operator/configobservation/cloudprovider/observe_cloudprovider.go +++ b/pkg/operator/configobservation/cloudprovider/observe_cloudprovider.go @@ -66,17 +66,22 @@ func ObserveCloudProviderNames(genericListers configobserver.Listers, recorder e sourceCloudConfigMap := infrastructure.Spec.CloudConfig.Name sourceCloudConfigNamespace := configNamespace + sourceLocation := resourcesynccontroller.ResourceLocation{ + Namespace: sourceCloudConfigNamespace, + Name: sourceCloudConfigMap, + } + + if len(sourceCloudConfigMap) == 0 { + sourceLocation = resourcesynccontroller.ResourceLocation{} + } err = listers.ResourceSyncer().SyncConfigMap( resourcesynccontroller.ResourceLocation{ Namespace: targetNamespaceName, Name: "cloud-config", }, - resourcesynccontroller.ResourceLocation{ - Namespace: sourceCloudConfigNamespace, - Name: sourceCloudConfigMap, - }, - ) + sourceLocation) + if err != nil { errs = append(errs, err) return observedConfig, errs diff --git a/pkg/operator/configobservation/cloudprovider/observe_cloudprovider_test.go b/pkg/operator/configobservation/cloudprovider/observe_cloudprovider_test.go index 9fd86e912..c3758191f 100644 --- a/pkg/operator/configobservation/cloudprovider/observe_cloudprovider_test.go +++ b/pkg/operator/configobservation/cloudprovider/observe_cloudprovider_test.go @@ -1,19 +1,31 @@ package cloudprovider import ( - "k8s.io/apimachinery/pkg/apis/meta/v1" "testing" + "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/client-go/tools/cache" configv1 "github.com/openshift/api/config/v1" configlistersv1 "github.com/openshift/client-go/config/listers/config/v1" "github.com/openshift/library-go/pkg/operator/events" + "github.com/openshift/library-go/pkg/operator/resourcesynccontroller" "github.com/openshift/cluster-kube-controller-manager-operator/pkg/operator/configobservation" ) +type FakeResourceSyncer struct{} + +func (fakeSyncer *FakeResourceSyncer) SyncConfigMap(destination, source resourcesynccontroller.ResourceLocation) error { + return nil +} + +func (fakeSyncer *FakeResourceSyncer) SyncSecret(destination, source resourcesynccontroller.ResourceLocation) error { + return nil +} + func TestObserveCloudProviderNames(t *testing.T) { cases := []struct { platform configv1.PlatformType @@ -47,6 +59,7 @@ func TestObserveCloudProviderNames(t *testing.T) { } listers := configobservation.Listers{ InfrastructureLister: configlistersv1.NewInfrastructureLister(indexer), + ResourceSync: &FakeResourceSyncer{}, } result, errs := ObserveCloudProviderNames(listers, events.NewInMemoryRecorder("cloud"), map[string]interface{}{}) if len(errs) > 0 {