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"
@@ -126,12 +125,12 @@ func TestCopyToNamespace(t *testing.T) {
126
125
Namespace : "bar" ,
127
126
Original : & v1alpha1.ClusterServiceVersion {
128
127
ObjectMeta : metav1.ObjectMeta {
129
- Name : "name" ,
128
+ Name : "name" ,
130
129
Namespace : "foo" ,
131
130
Labels : map [string ]string {
132
131
"operators.coreos.com/foo" : "" ,
133
132
"operators.coreos.com/bar" : "" ,
134
- "untouched" : "fine" ,
133
+ "untouched" : "fine" ,
135
134
},
136
135
},
137
136
},
@@ -142,25 +141,25 @@ func TestCopyToNamespace(t *testing.T) {
142
141
Labels : map [string ]string {
143
142
"operators.coreos.com/foo" : "" ,
144
143
"operators.coreos.com/bar" : "" ,
145
- "untouched" : "fine" ,
144
+ "untouched" : "fine" ,
146
145
},
147
146
},
148
147
Status : v1alpha1.ClusterServiceVersionStatus {
149
- Message : "The operator is running in foo but is managing this namespace" ,
150
- Reason : v1alpha1 .CSVReasonCopied },
148
+ Message : "The operator is running in foo but is managing this namespace" ,
149
+ Reason : v1alpha1 .CSVReasonCopied },
151
150
},
152
151
ExpectedResult : & v1alpha1.ClusterServiceVersion {
153
152
ObjectMeta : metav1.ObjectMeta {
154
153
Name : "name" ,
155
154
Namespace : "bar" ,
156
155
Labels : map [string ]string {
157
- "untouched" : "fine" ,
156
+ "untouched" : "fine" ,
158
157
"olm.copiedFrom" : "foo" ,
159
158
},
160
159
},
161
160
Status : v1alpha1.ClusterServiceVersionStatus {
162
- Message : "The operator is running in foo but is managing this namespace" ,
163
- Reason : v1alpha1 .CSVReasonCopied ,
161
+ Message : "The operator is running in foo but is managing this namespace" ,
162
+ Reason : v1alpha1 .CSVReasonCopied ,
164
163
},
165
164
},
166
165
ExpectedActions : []ktesting.Action {
@@ -169,7 +168,63 @@ func TestCopyToNamespace(t *testing.T) {
169
168
Name : "name" ,
170
169
Namespace : "bar" ,
171
170
Labels : map [string ]string {
172
- "untouched" : "fine" ,
171
+ "untouched" : "fine" ,
172
+ "olm.copiedFrom" : "foo" ,
173
+ },
174
+ },
175
+ Status : v1alpha1.ClusterServiceVersionStatus {
176
+ Message : "The operator is running in foo but is managing this namespace" ,
177
+ Reason : v1alpha1 .CSVReasonCopied ,
178
+ },
179
+ }),
180
+ },
181
+ },
182
+ {
183
+ Name : "component labels are stripped before initial copy" ,
184
+ Namespace : "bar" ,
185
+ Original : & v1alpha1.ClusterServiceVersion {
186
+ ObjectMeta : metav1.ObjectMeta {
187
+ Name : "name" ,
188
+ Namespace : "foo" ,
189
+ Labels : map [string ]string {
190
+ "operators.coreos.com/foo" : "" ,
191
+ "operators.coreos.com/bar" : "" ,
192
+ "untouched" : "fine" ,
193
+ },
194
+ },
195
+ },
196
+ ExistingCopy : nil ,
197
+ ExpectedResult : & 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
+ },
211
+ ExpectedActions : []ktesting.Action {
212
+ ktesting .NewCreateAction (gvr , "bar" , & v1alpha1.ClusterServiceVersion {
213
+ ObjectMeta : metav1.ObjectMeta {
214
+ Name : "name" ,
215
+ Namespace : "bar" ,
216
+ Labels : map [string ]string {
217
+ "untouched" : "fine" ,
218
+ "olm.copiedFrom" : "foo" ,
219
+ },
220
+ },
221
+ }),
222
+ ktesting .NewUpdateSubresourceAction (gvr , "status" , "bar" , & v1alpha1.ClusterServiceVersion {
223
+ ObjectMeta : metav1.ObjectMeta {
224
+ Name : "name" ,
225
+ Namespace : "bar" ,
226
+ Labels : map [string ]string {
227
+ "untouched" : "fine" ,
173
228
"olm.copiedFrom" : "foo" ,
174
229
},
175
230
},
@@ -190,10 +245,11 @@ func TestCopyToNamespace(t *testing.T) {
190
245
if tc .ExistingCopy != nil {
191
246
client = fake .NewSimpleClientset (tc .ExistingCopy )
192
247
v1alpha1lister .ClusterServiceVersionListerReturns (FakeClusterServiceVersionLister {tc .ExistingCopy })
248
+ } else {
249
+ v1alpha1lister .ClusterServiceVersionListerReturns (FakeClusterServiceVersionLister (nil ))
193
250
}
194
251
195
- logger := logrus .New ()
196
- logger .SetOutput (ioutil .Discard )
252
+ logger , _ := test .NewNullLogger ()
197
253
198
254
o := & Operator {
199
255
lister : lister ,
0 commit comments