1
1
package olm
2
2
3
3
import (
4
- "io/ioutil"
5
4
"testing"
6
5
"time"
7
6
8
- "github.com/sirupsen/logrus"
7
+ "github.com/sirupsen/logrus/hooks/test "
9
8
"github.com/stretchr/testify/require"
10
9
11
10
"k8s.io/apimachinery/pkg/api/errors"
@@ -74,6 +73,20 @@ func TestCopyToNamespace(t *testing.T) {
74
73
},
75
74
},
76
75
ExpectedActions : []ktesting.Action {
76
+ ktesting .NewCreateAction (gvr , "bar" , & v1alpha1.ClusterServiceVersion {
77
+ ObjectMeta : metav1.ObjectMeta {
78
+ Name : "name" ,
79
+ Namespace : "bar" ,
80
+ Labels : map [string ]string {
81
+ "olm.copiedFrom" : "foo" ,
82
+ },
83
+ },
84
+ Status : v1alpha1.ClusterServiceVersionStatus {
85
+ LastUpdateTime : & metav1.Time {Time : time .Unix (2 , 0 )},
86
+ Message : "The operator is running in foo but is managing this namespace" ,
87
+ Reason : v1alpha1 .CSVReasonCopied ,
88
+ },
89
+ }),
77
90
ktesting .NewUpdateSubresourceAction (gvr , "status" , "bar" , & v1alpha1.ClusterServiceVersion {
78
91
ObjectMeta : metav1.ObjectMeta {
79
92
Name : "name" ,
@@ -107,7 +120,8 @@ func TestCopyToNamespace(t *testing.T) {
107
120
Status : v1alpha1.ClusterServiceVersionStatus {
108
121
LastUpdateTime : & metav1.Time {Time : time .Unix (2 , 0 )},
109
122
Message : "The operator is running in foo but is managing this namespace" ,
110
- Reason : v1alpha1 .CSVReasonCopied },
123
+ Reason : v1alpha1 .CSVReasonCopied ,
124
+ },
111
125
},
112
126
ExpectedResult : & v1alpha1.ClusterServiceVersion {
113
127
ObjectMeta : metav1.ObjectMeta {
@@ -120,18 +134,34 @@ func TestCopyToNamespace(t *testing.T) {
120
134
Reason : v1alpha1 .CSVReasonCopied ,
121
135
},
122
136
},
137
+ ExpectedActions : []ktesting.Action {
138
+ ktesting .NewCreateAction (gvr , "bar" , & v1alpha1.ClusterServiceVersion {
139
+ ObjectMeta : metav1.ObjectMeta {
140
+ Name : "name" ,
141
+ Namespace : "bar" ,
142
+ Labels : map [string ]string {
143
+ "olm.copiedFrom" : "foo" ,
144
+ },
145
+ },
146
+ Status : v1alpha1.ClusterServiceVersionStatus {
147
+ LastUpdateTime : & metav1.Time {Time : time .Unix (2 , 0 )},
148
+ Message : "The operator is running in foo but is managing this namespace" ,
149
+ Reason : v1alpha1 .CSVReasonCopied ,
150
+ },
151
+ }),
152
+ },
123
153
},
124
154
{
125
- Name : "component labels are stripped before copy" ,
155
+ Name : "component labels are stripped before updating copy" ,
126
156
Namespace : "bar" ,
127
157
Original : & v1alpha1.ClusterServiceVersion {
128
158
ObjectMeta : metav1.ObjectMeta {
129
- Name : "name" ,
159
+ Name : "name" ,
130
160
Namespace : "foo" ,
131
161
Labels : map [string ]string {
132
162
"operators.coreos.com/foo" : "" ,
133
163
"operators.coreos.com/bar" : "" ,
134
- "untouched" : "fine" ,
164
+ "untouched" : "fine" ,
135
165
},
136
166
},
137
167
},
@@ -142,40 +172,100 @@ func TestCopyToNamespace(t *testing.T) {
142
172
Labels : map [string ]string {
143
173
"operators.coreos.com/foo" : "" ,
144
174
"operators.coreos.com/bar" : "" ,
145
- "untouched" : "fine" ,
175
+ "untouched" : "fine" ,
146
176
},
147
177
},
148
178
Status : v1alpha1.ClusterServiceVersionStatus {
149
- Message : "The operator is running in foo but is managing this namespace" ,
150
- Reason : v1alpha1 .CSVReasonCopied },
179
+ Message : "The operator is running in foo but is managing this namespace" ,
180
+ Reason : v1alpha1 .CSVReasonCopied },
151
181
},
152
182
ExpectedResult : & v1alpha1.ClusterServiceVersion {
153
183
ObjectMeta : metav1.ObjectMeta {
154
184
Name : "name" ,
155
185
Namespace : "bar" ,
156
186
Labels : map [string ]string {
157
- "untouched" : "fine" ,
187
+ "untouched" : "fine" ,
158
188
"olm.copiedFrom" : "foo" ,
159
189
},
160
190
},
161
191
Status : v1alpha1.ClusterServiceVersionStatus {
162
- Message : "The operator is running in foo but is managing this namespace" ,
163
- Reason : v1alpha1 .CSVReasonCopied ,
192
+ Message : "The operator is running in foo but is managing this namespace" ,
193
+ Reason : v1alpha1 .CSVReasonCopied ,
164
194
},
165
195
},
166
196
ExpectedActions : []ktesting.Action {
197
+ ktesting .NewCreateAction (gvr , "bar" , & v1alpha1.ClusterServiceVersion {
198
+ ObjectMeta : metav1.ObjectMeta {
199
+ Name : "name" ,
200
+ Namespace : "bar" ,
201
+ Labels : map [string ]string {
202
+ "untouched" : "fine" ,
203
+ "olm.copiedFrom" : "foo" ,
204
+ },
205
+ },
206
+ Status : v1alpha1.ClusterServiceVersionStatus {
207
+ Message : "The operator is running in foo but is managing this namespace" ,
208
+ Reason : v1alpha1 .CSVReasonCopied ,
209
+ },
210
+ }),
167
211
ktesting .NewUpdateAction (gvr , "bar" , & v1alpha1.ClusterServiceVersion {
168
212
ObjectMeta : metav1.ObjectMeta {
169
213
Name : "name" ,
170
214
Namespace : "bar" ,
171
215
Labels : map [string ]string {
172
- "untouched" : "fine" ,
216
+ "untouched" : "fine" ,
173
217
"olm.copiedFrom" : "foo" ,
174
218
},
175
219
},
176
220
Status : v1alpha1.ClusterServiceVersionStatus {
177
- Message : "The operator is running in foo but is managing this namespace" ,
178
- Reason : v1alpha1 .CSVReasonCopied ,
221
+ Message : "The operator is running in foo but is managing this namespace" ,
222
+ Reason : v1alpha1 .CSVReasonCopied ,
223
+ },
224
+ }),
225
+ },
226
+ },
227
+ {
228
+ Name : "component labels are stripped before initial copy" ,
229
+ Namespace : "bar" ,
230
+ Original : & v1alpha1.ClusterServiceVersion {
231
+ ObjectMeta : metav1.ObjectMeta {
232
+ Name : "name" ,
233
+ Namespace : "foo" ,
234
+ Labels : map [string ]string {
235
+ "operators.coreos.com/foo" : "" ,
236
+ "operators.coreos.com/bar" : "" ,
237
+ "untouched" : "fine" ,
238
+ },
239
+ },
240
+ },
241
+ ExistingCopy : nil ,
242
+ ExpectedResult : & v1alpha1.ClusterServiceVersion {
243
+ ObjectMeta : metav1.ObjectMeta {
244
+ Name : "name" ,
245
+ Namespace : "bar" ,
246
+ Labels : map [string ]string {
247
+ "untouched" : "fine" ,
248
+ "olm.copiedFrom" : "foo" ,
249
+ },
250
+ },
251
+ Status : v1alpha1.ClusterServiceVersionStatus {
252
+ Message : "The operator is running in foo but is managing this namespace" ,
253
+ Reason : v1alpha1 .CSVReasonCopied ,
254
+ },
255
+ },
256
+ ExpectedActions : []ktesting.Action {
257
+ ktesting .NewCreateAction (gvr , "bar" , & v1alpha1.ClusterServiceVersion {
258
+ ObjectMeta : metav1.ObjectMeta {
259
+ Name : "name" ,
260
+ Namespace : "bar" ,
261
+ Labels : map [string ]string {
262
+ "untouched" : "fine" ,
263
+ "olm.copiedFrom" : "foo" ,
264
+ },
265
+ },
266
+ Status : v1alpha1.ClusterServiceVersionStatus {
267
+ Message : "The operator is running in foo but is managing this namespace" ,
268
+ Reason : v1alpha1 .CSVReasonCopied ,
179
269
},
180
270
}),
181
271
},
@@ -192,8 +282,7 @@ func TestCopyToNamespace(t *testing.T) {
192
282
v1alpha1lister .ClusterServiceVersionListerReturns (FakeClusterServiceVersionLister {tc .ExistingCopy })
193
283
}
194
284
195
- logger := logrus .New ()
196
- logger .SetOutput (ioutil .Discard )
285
+ logger , _ := test .NewNullLogger ()
197
286
198
287
o := & Operator {
199
288
lister : lister ,
0 commit comments