@@ -3,6 +3,7 @@ package e2e_test
3
3
import (
4
4
"context"
5
5
"database/sql"
6
+ "fmt"
6
7
"io/ioutil"
7
8
"os"
8
9
"os/exec"
@@ -15,6 +16,9 @@ import (
15
16
"k8s.io/apimachinery/pkg/util/rand"
16
17
17
18
"github.com/operator-framework/operator-registry/pkg/containertools"
19
+ "github.com/operator-framework/operator-registry/pkg/image"
20
+ "github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
21
+ "github.com/operator-framework/operator-registry/pkg/image/execregistry"
18
22
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
19
23
"github.com/operator-framework/operator-registry/pkg/lib/indexer"
20
24
"github.com/operator-framework/operator-registry/pkg/sqlite"
@@ -133,19 +137,6 @@ func pushWith(containerTool, image string) error {
133
137
return dockerpush .Run ()
134
138
}
135
139
136
- func pushBundles (containerTool string ) error {
137
- err := pushWith (containerTool , bundleImage + ":" + bundleTag1 )
138
- if err != nil {
139
- return err
140
- }
141
- err = pushWith (containerTool , bundleImage + ":" + bundleTag2 )
142
- if err != nil {
143
- return err
144
- }
145
- err = pushWith (containerTool , bundleImage + ":" + bundleTag3 )
146
- return err
147
- }
148
-
149
140
func exportWith (containerTool string ) error {
150
141
logger := logrus .WithFields (logrus.Fields {"package" : packageName })
151
142
indexExporter := indexer .NewIndexExporter (containertools .NewContainerTool (containerTool , containertools .NoneTool ), logger )
@@ -197,22 +188,65 @@ var _ = Describe("opm", func() {
197
188
Expect (err ).NotTo (HaveOccurred (), "Error logging into quay.io" )
198
189
})
199
190
191
+ It ("builds and validates a bundle image" , func () {
192
+ By ("building bundle" )
193
+ img := bundleImage + ":" + bundleTag3
194
+ err := inTemporaryBuildContext (func () error {
195
+ return bundle .BuildFunc (bundlePath3 , "" , img , containerTool , packageName , channels , defaultChannel , false )
196
+ })
197
+ Expect (err ).NotTo (HaveOccurred ())
198
+
199
+ By ("pushing bundle" )
200
+ Expect (pushWith (containerTool , img )).To (Succeed ())
201
+
202
+ By ("pulling bundle" )
203
+ logger := logrus .WithFields (logrus.Fields {"image" : img })
204
+ tool := containertools .NewContainerTool (containerTool , containertools .NoneTool )
205
+ var registry image.Registry
206
+ switch tool {
207
+ case containertools .PodmanTool , containertools .DockerTool :
208
+ registry , err = execregistry .NewRegistry (tool , logger )
209
+ case containertools .NoneTool :
210
+ registry , err = containerdregistry .NewRegistry (containerdregistry .WithLog (logger ))
211
+ default :
212
+ err = fmt .Errorf ("unrecognized container-tool option: %s" , containerTool )
213
+ }
214
+ Expect (err ).NotTo (HaveOccurred ())
215
+
216
+ unpackDir , err := ioutil .TempDir ("." , bundleTag3 )
217
+ Expect (err ).NotTo (HaveOccurred ())
218
+ validator := bundle .NewImageValidator (registry , logger )
219
+ Expect (validator .PullBundleImage (img , unpackDir )).To (Succeed ())
220
+
221
+ By ("validating bundle format" )
222
+ Expect (validator .ValidateBundleFormat (unpackDir )).To (Succeed ())
223
+
224
+ By ("validating bundle content" )
225
+ manifestsDir := filepath .Join (unpackDir , bundle .ManifestsDir )
226
+ Expect (validator .ValidateBundleContent (manifestsDir )).To (Succeed ())
227
+ Expect (os .RemoveAll (unpackDir )).To (Succeed ())
228
+ })
229
+
200
230
It ("builds and manipulates bundle and index images" , func () {
201
231
By ("building bundles" )
202
- for tag , path := range map [string ]string {
232
+ tagPaths := map [string ]string {
203
233
bundleTag1 : bundlePath1 ,
204
234
bundleTag2 : bundlePath2 ,
205
235
bundleTag3 : bundlePath3 ,
206
- } {
207
- err := inTemporaryBuildContext (func () error {
236
+ }
237
+ var err error
238
+ for tag , path := range tagPaths {
239
+ err = inTemporaryBuildContext (func () error {
208
240
return bundle .BuildFunc (path , "" , bundleImage + ":" + tag , containerTool , packageName , channels , defaultChannel , false )
209
241
})
210
242
Expect (err ).NotTo (HaveOccurred ())
211
243
}
212
244
213
245
By ("pushing bundles" )
214
- err := pushBundles (containerTool )
215
- Expect (err ).NotTo (HaveOccurred ())
246
+ for tag , _ := range tagPaths {
247
+ err = pushWith (containerTool , bundleImage + ":" + tag )
248
+ Expect (err ).NotTo (HaveOccurred ())
249
+ }
216
250
217
251
By ("building an index" )
218
252
err = buildIndexWith (containerTool , indexImage1 , bundleImage , []string {bundleTag1 , bundleTag2 })
0 commit comments