Skip to content

Commit

Permalink
Fix unit test panic
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufied committed Apr 3, 2019
1 parent 6cac9ff commit 429720e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 429720e

Please sign in to comment.