Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Peeler committed Oct 10, 2018
1 parent e88a316 commit 09ef2c4
Showing 1 changed file with 64 additions and 10 deletions.
74 changes: 64 additions & 10 deletions pkg/controller/operators/olm/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ func TestSyncOperatorGroups(t *testing.T) {

tests := []struct {
name string
expectedEqual bool
initialCsvs []runtime.Object
initialCrds []runtime.Object
initialObjs []runtime.Object
Expand All @@ -1013,7 +1014,8 @@ func TestSyncOperatorGroups(t *testing.T) {
expectedAnnotation map[string]string
}{
{
name: "operator group with no matching namespace, no CSVs",
name: "operator group with no matching namespace, no CSVs",
expectedEqual: true,
namespaces: []v1.Namespace{
{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1036,7 +1038,8 @@ func TestSyncOperatorGroups(t *testing.T) {
expectedStatus: v1alpha2.OperatorGroupStatus{},
},
{
name: "operator group with matching namespace, no CSVs",
name: "operator group with matching namespace, no CSVs",
expectedEqual: true,
namespaces: []v1.Namespace{
{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1072,7 +1075,8 @@ func TestSyncOperatorGroups(t *testing.T) {
},
},
{
name: "operator group with matching namespace, CSV present",
name: "operator group with matching namespace, CSV present",
expectedEqual: false,
namespaces: []v1.Namespace{
{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1118,8 +1122,57 @@ func TestSyncOperatorGroups(t *testing.T) {
},
LastUpdated: timeNow(),
},
//expectedAnnotation: map[string]string{"olm.targetNamespaces": testNS},
expectedAnnotation: map[string]string{"BROKEN": testNS},
expectedAnnotation: map[string]string{"NOTFOUND": testNS},
},
{
name: "operator group with matching namespace, CSV present",
expectedEqual: true,
namespaces: []v1.Namespace{
{
ObjectMeta: metav1.ObjectMeta{
Name: testNS,
Labels: aLabel,
},
},
},
initialCsvs: []runtime.Object{
csv("csv1",
testNS,
"",
installStrategy("csv1-dep1"),
[]*v1beta1.CustomResourceDefinition{crd("c1", "v1")},
[]*v1beta1.CustomResourceDefinition{},
v1alpha1.CSVPhaseSucceeded,
),
},
initialObjs: []runtime.Object{
deployment("csv1-dep1", testNS),
},
inputGroup: v1alpha2.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "operator-group-1",
Namespace: testNS,
Labels: aLabel,
},
Spec: v1alpha2.OperatorGroupSpec{
Selector: metav1.LabelSelector{
MatchLabels: aLabel,
},
},
},
expectedStatus: v1alpha2.OperatorGroupStatus{
Namespaces: []v1.Namespace{
{
ObjectMeta: metav1.ObjectMeta{
Name: testNS,
Labels: aLabel,
Annotations: map[string]string{"test": "annotation"},
},
},
},
LastUpdated: timeNow(),
},
expectedAnnotation: map[string]string{"olm.targetNamespaces": testNS},
},
}

Expand All @@ -1134,6 +1187,7 @@ func TestSyncOperatorGroups(t *testing.T) {
for _, informer := range []cache.SharedIndexInformer{deployInformer.Informer()} {
go informer.Run(stopCh)
}
op.deploymentLister[testNS] = deployInformer.Lister()
informerFactory.Start(stopCh)
informerFactory.WaitForCacheSync(stopCh)

Expand All @@ -1145,18 +1199,18 @@ func TestSyncOperatorGroups(t *testing.T) {
// assuming CSVs are in correct namespace
for _, ns := range tc.namespaces {
deployments, err := op.deploymentLister[ns.Name].List(labels.Everything())
//deployments, err := op.OpClient.KubernetesInterface().AppsV1().Deployments(ns.Name).List(metav1.ListOptions{})
if err != nil {
t.Fatal(err)
}
t.Logf("JPEELER deployments in test using ns: %v: %v\n", ns.Name, deployments)
for _, deploy := range deployments {
assert.Equal(t, tc.expectedAnnotation, deploy.Spec.Template.Annotations)
if tc.expectedEqual {
assert.Equal(t, tc.expectedAnnotation, deploy.Spec.Template.Annotations)
} else {
assert.NotEqual(t, tc.expectedAnnotation, deploy.Spec.Template.Annotations)
}
}
}
}
close(stopCh)
<-stopCh
})
}
}
Expand Down

0 comments on commit 09ef2c4

Please sign in to comment.