@@ -77,6 +77,70 @@ func (m *mockTransitioner) ExecutePlan(plan *v1alpha1.InstallPlan) error {
77
77
return m .err
78
78
}
79
79
80
+ func TestCreateInstallPlanHasExpectedClusterServiceVersionNames (t * testing.T ) {
81
+ namespace := "foo"
82
+ tests := []struct {
83
+ testName string
84
+ steps []* v1alpha1.Step
85
+ bundleLookups []v1alpha1.BundleLookup
86
+ expectedClusterServiceVersionNames []string
87
+ }{
88
+ /******************************************************************************
89
+ Historically, when creating an installPlan it's spec.ClusterServiceVersionNames
90
+ was derived from two sources:
91
+ 1. The names of CSVs found in "steps" of the installPlan's status.plan
92
+ 2. The metadata associated with the bundle image
93
+
94
+ These sources couldn't result in duplicate entries as the unpacking job would
95
+ finish after the installPlan was created and the steps weren't populated until
96
+ the unpacking job finished.
97
+
98
+ OLM was later updated to complete the unpacking jobs prior to creating
99
+ the installPlan, which caused CSVs to be listed twice as the createInstallPlan
100
+ function was called with steps and a bundle.
101
+ *****************************************************************************/
102
+ {
103
+ testName : "Check that CSVs are not listed twice if steps and bundles are provided" ,
104
+ steps : []* v1alpha1.Step {{
105
+ Resolving : "csv" ,
106
+ Resource : v1alpha1.StepResource {
107
+ CatalogSource : "catalog" ,
108
+ CatalogSourceNamespace : namespace ,
109
+ Group : "operators.coreos.com" ,
110
+ Version : "v1alpha1" ,
111
+ Kind : "ClusterServiceVersion" ,
112
+ Name : "csvA" ,
113
+ Manifest : toManifest (t , csv ("csvA" , namespace , nil , nil )),
114
+ },
115
+ Status : v1alpha1 .StepStatusUnknown ,
116
+ }},
117
+ bundleLookups : []v1alpha1.BundleLookup {
118
+ {
119
+ Identifier : "csvA" ,
120
+ },
121
+ },
122
+ expectedClusterServiceVersionNames : []string {"csvA" },
123
+ },
124
+ }
125
+ for _ , tt := range tests {
126
+ t .Run (tt .testName , func (t * testing.T ) {
127
+ ctx , cancel := context .WithCancel (context .TODO ())
128
+ defer cancel ()
129
+
130
+ op , err := NewFakeOperator (ctx , namespace , []string {namespace })
131
+ require .NoError (t , err )
132
+
133
+ _ , err = op .createInstallPlan (namespace , 0 , nil , v1alpha1 .ApprovalAutomatic , tt .steps , tt .bundleLookups )
134
+ require .NoError (t , err )
135
+
136
+ ipList , err := op .client .OperatorsV1alpha1 ().InstallPlans (namespace ).List (ctx , metav1.ListOptions {})
137
+ require .NoError (t , err )
138
+ require .Len (t , ipList .Items , 1 )
139
+ require .Equal (t , tt .expectedClusterServiceVersionNames , ipList .Items [0 ].Spec .ClusterServiceVersionNames )
140
+ })
141
+ }
142
+ }
143
+
80
144
func TestTransitionInstallPlan (t * testing.T ) {
81
145
errMsg := "transition test error"
82
146
err := errors .New (errMsg )
0 commit comments