@@ -19,6 +19,7 @@ import (
19
19
"io/ioutil"
20
20
"os"
21
21
"path/filepath"
22
+ "strings"
22
23
23
24
. "github.com/onsi/ginkgo"
24
25
. "github.com/onsi/gomega"
59
60
cfg * config.Config
60
61
)
61
62
63
+ const (
64
+ testSDKbuilderStamp = "operators.operatorframework.io/builder: operator-sdk-unknown"
65
+ testSDKlayoutStamp = "operators.operatorframework.io/project_layout: unknown"
66
+ )
67
+
62
68
var (
63
69
baseCSV , baseCSVUIMeta , newCSV * v1alpha1.ClusterServiceVersion
64
70
baseCSVStr , baseCSVUIMetaStr , newCSVStr string
@@ -121,7 +127,8 @@ var _ = Describe("Generating a ClusterServiceVersion", func() {
121
127
WithWriter (buf ),
122
128
}
123
129
Expect (g .Generate (cfg , opts ... )).ToNot (HaveOccurred ())
124
- Expect (buf .String ()).To (MatchYAML (newCSVStr ))
130
+ outputCSV := removeSDKLabelsFromCSVString (buf .String ())
131
+ Expect (outputCSV ).To (MatchYAML (newCSVStr ))
125
132
})
126
133
It ("should write a ClusterServiceVersion manifest to a base file" , func () {
127
134
g = Generator {
@@ -135,7 +142,27 @@ var _ = Describe("Generating a ClusterServiceVersion", func() {
135
142
Expect (g .Generate (cfg , opts ... )).ToNot (HaveOccurred ())
136
143
outputFile := filepath .Join (tmp , "bases" , makeCSVFileName (operatorName ))
137
144
Expect (outputFile ).To (BeAnExistingFile ())
138
- Expect (string (readFileHelper (outputFile ))).To (MatchYAML (baseCSVUIMetaStr ))
145
+ Expect (readFileHelper (outputFile )).To (MatchYAML (baseCSVUIMetaStr ))
146
+ })
147
+ It ("should have sdk labels in annotations" , func () {
148
+ g = Generator {
149
+ OperatorName : operatorName ,
150
+ OperatorType : operatorType ,
151
+ }
152
+ opts := []Option {
153
+ WithBase (csvBasesDir , goAPIsDir , projutil .InteractiveHardOff ),
154
+ WithBaseWriter (tmp ),
155
+ }
156
+ Expect (g .Generate (cfg , opts ... )).ToNot (HaveOccurred ())
157
+ outputFile := filepath .Join (tmp , "bases" , makeCSVFileName (operatorName ))
158
+ outputCSV , _ , err := getCSVFromFile (outputFile )
159
+ Expect (err ).ToNot (HaveOccurred ())
160
+ Expect (outputFile ).To (BeAnExistingFile ())
161
+
162
+ annotations := outputCSV .GetAnnotations ()
163
+ Expect (annotations ).ToNot (BeNil ())
164
+ Expect (annotations ).Should (HaveKey (projutil .OperatorBuilder ))
165
+ Expect (annotations ).Should (HaveKey (projutil .OperatorLayout ))
139
166
})
140
167
It ("should write a ClusterServiceVersion manifest to a bundle file" , func () {
141
168
g = Generator {
@@ -151,7 +178,7 @@ var _ = Describe("Generating a ClusterServiceVersion", func() {
151
178
Expect (g .Generate (cfg , opts ... )).ToNot (HaveOccurred ())
152
179
outputFile := filepath .Join (tmp , bundle .ManifestsDir , makeCSVFileName (operatorName ))
153
180
Expect (outputFile ).To (BeAnExistingFile ())
154
- Expect (string ( readFileHelper (outputFile ) )).To (MatchYAML (newCSVStr ))
181
+ Expect (readFileHelper (outputFile )).To (MatchYAML (newCSVStr ))
155
182
})
156
183
It ("should write a ClusterServiceVersion manifest to a package file" , func () {
157
184
g = Generator {
@@ -167,7 +194,7 @@ var _ = Describe("Generating a ClusterServiceVersion", func() {
167
194
Expect (g .Generate (cfg , opts ... )).ToNot (HaveOccurred ())
168
195
outputFile := filepath .Join (tmp , g .Version , makeCSVFileName (operatorName ))
169
196
Expect (outputFile ).To (BeAnExistingFile ())
170
- Expect (string ( readFileHelper (outputFile ) )).To (MatchYAML (newCSVStr ))
197
+ Expect (readFileHelper (outputFile )).To (MatchYAML (newCSVStr ))
171
198
})
172
199
173
200
It ("should write a ClusterServiceVersion manifest to a legacy bundle file" , func () {
@@ -184,7 +211,7 @@ var _ = Describe("Generating a ClusterServiceVersion", func() {
184
211
Expect (g .GenerateLegacy (opts ... )).ToNot (HaveOccurred ())
185
212
outputFile := filepath .Join (tmp , bundle .ManifestsDir , makeCSVFileName (operatorName ))
186
213
Expect (outputFile ).To (BeAnExistingFile ())
187
- Expect (string ( readFileHelper (outputFile ) )).To (MatchYAML (newCSVStr ))
214
+ Expect (readFileHelper (outputFile )).To (MatchYAML (newCSVStr ))
188
215
})
189
216
It ("should write a ClusterServiceVersion manifest as a legacy package file" , func () {
190
217
g = Generator {
@@ -332,7 +359,6 @@ var _ = Describe("Generating a ClusterServiceVersion", func() {
332
359
Expect (csv ).To (Equal (upgradeCSV (newCSV , g .OperatorName , g .Version )))
333
360
})
334
361
})
335
-
336
362
})
337
363
338
364
})
@@ -397,10 +423,10 @@ func initTestCSVsHelper() {
397
423
ExpectWithOffset (1 , err ).ToNot (HaveOccurred ())
398
424
}
399
425
400
- func readFileHelper (path string ) [] byte {
426
+ func readFileHelper (path string ) string {
401
427
b , err := ioutil .ReadFile (path )
402
428
ExpectWithOffset (1 , err ).ToNot (HaveOccurred ())
403
- return b
429
+ return removeSDKLabelsFromCSVString ( string ( b ))
404
430
}
405
431
406
432
func modifyCSVDepImageHelper (tag string ) func (csv * v1alpha1.ClusterServiceVersion ) {
@@ -469,3 +495,11 @@ func upgradeCSV(csv *v1alpha1.ClusterServiceVersion, name, version string) *v1al
469
495
470
496
return upgraded
471
497
}
498
+
499
+ // removeSDKLabelsFromCSVString to remove the sdk labels from test CSV structs. The test
500
+ // cases do not generate a PROJECTFILE or an entire operator to get the version or layout
501
+ // of SDK. Hence the values of those will appear "unknown".
502
+ func removeSDKLabelsFromCSVString (csv string ) string {
503
+ replacer := strings .NewReplacer (testSDKbuilderStamp , "" , testSDKlayoutStamp , "" )
504
+ return replacer .Replace (csv )
505
+ }
0 commit comments