github.com/dean7474/operator-registry@v1.21.1-0.20220418203638-d4717f98c2e5/test/e2e/opm_bundle_test.go (about) 1 package e2e_test 2 3 import ( 4 "bytes" 5 "context" 6 "io/ioutil" 7 "os" 8 "path/filepath" 9 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 "golang.org/x/mod/sumdb/dirhash" 13 14 libimage "github.com/operator-framework/operator-registry/pkg/lib/image" 15 ) 16 17 var _ = Describe("opm alpha bundle", func() { 18 // out captures opm command output 19 var out bytes.Buffer 20 21 BeforeEach(func() { 22 // Reset the command's output buffer 23 out = bytes.Buffer{} 24 opm.SetOut(&out) 25 opm.SetErr(&out) 26 }) 27 28 Context("for an invalid bundle", func() { 29 var ( 30 bundleRef string 31 bundleChecksum string 32 tmpDir string 33 rootCA string 34 stopRegistry func() 35 ) 36 37 BeforeEach(func() { 38 ctx, cancel := context.WithCancel(context.Background()) 39 stopRegistry = func() { 40 cancel() 41 <-ctx.Done() 42 } 43 44 // Spin up an in-process docker registry with a set of preconfigured test images 45 var ( 46 // Directory containing the docker registry filesystem 47 goldenFiles = "../../pkg/image/testdata/golden" 48 49 host string 50 err error 51 ) 52 host, rootCA, err = libimage.RunDockerRegistry(ctx, goldenFiles) 53 Expect(err).ToNot(HaveOccurred()) 54 55 // Create a bundle ref using the local registry host name and the namespace/name of a bundle we already know the content of 56 bundleRef = host + "/olmtest/kiali@sha256:a1bec450c104ceddbb25b252275eb59f1f1e6ca68e0ced76462042f72f7057d8" 57 58 // Generate a checksum of the expected content for the bundle under test 59 bundleChecksum, err = dirhash.HashDir(filepath.Join(goldenFiles, "bundles/kiali"), "", dirhash.DefaultHash) 60 Expect(err).ToNot(HaveOccurred()) 61 62 // Set up a temporary directory that we can use for testing 63 tmpDir, err = ioutil.TempDir("", "opm-alpha-bundle-") 64 Expect(err).ToNot(HaveOccurred()) 65 }) 66 67 AfterEach(func() { 68 stopRegistry() 69 if CurrentGinkgoTestDescription().Failed { 70 // Skip additional cleanup 71 return 72 } 73 74 Expect(os.RemoveAll(tmpDir)).To(Succeed()) 75 }) 76 77 // Note(tflannag): See https://github.com/operator-framework/operator-registry/issues/609. 78 PIt("fails to unpack", func() { 79 unpackDir := filepath.Join(tmpDir, "unpacked") 80 opm.SetArgs([]string{ 81 "alpha", 82 "bundle", 83 "unpack", 84 "--root-ca", 85 rootCA, 86 "--out", 87 unpackDir, 88 bundleRef, 89 }) 90 91 Expect(opm.Execute()).ToNot(Succeed()) 92 result, err := ioutil.ReadAll(&out) 93 Expect(err).ToNot(HaveOccurred()) 94 Expect(string(result)).To(ContainSubstring("bundle content validation failed")) 95 }) 96 97 PIt("unpacks successfully", func() { 98 By("setting --skip-validation") 99 100 unpackDir := filepath.Join(tmpDir, "unpacked") 101 opm.SetArgs([]string{ 102 "alpha", 103 "bundle", 104 "unpack", 105 "--root-ca", 106 rootCA, 107 "--out", 108 unpackDir, 109 bundleRef, 110 "--skip-validation", 111 }) 112 113 Expect(opm.Execute()).To(Succeed()) 114 result, err := ioutil.ReadAll(&out) 115 Expect(err).ToNot(HaveOccurred()) 116 Expect(result).ToNot(ContainSubstring("bundle content validation failed")) 117 118 checksum, err := dirhash.HashDir(unpackDir, "", dirhash.DefaultHash) 119 Expect(err).ToNot(HaveOccurred()) 120 Expect(checksum).To(Equal(bundleChecksum)) 121 }) 122 }) 123 })