github.com/yimialmonte/fabric@v2.1.1+incompatible/core/container/externalbuilder/metadataprovider_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package externalbuilder_test 8 9 import ( 10 "archive/tar" 11 "bytes" 12 "io" 13 14 . "github.com/onsi/ginkgo" 15 . "github.com/onsi/gomega" 16 17 "github.com/hyperledger/fabric/core/container/externalbuilder" 18 ) 19 20 var _ = Describe("Metadataprovider", func() { 21 var mp *externalbuilder.MetadataProvider 22 23 BeforeEach(func() { 24 mp = &externalbuilder.MetadataProvider{ 25 DurablePath: "testdata", 26 } 27 }) 28 29 It("packages up the metadata", func() { 30 data, err := mp.PackageMetadata("persisted_build") 31 Expect(err).NotTo(HaveOccurred()) 32 tr := tar.NewReader(bytes.NewBuffer(data)) 33 34 headerSizes := map[string]int64{ 35 "META-INF/": 0, 36 "META-INF/index.json": 3, 37 } 38 39 headers := 0 40 for { 41 header, err := tr.Next() 42 if err != nil { 43 Expect(err).To(Equal(io.EOF)) 44 break 45 } 46 47 headers++ 48 By("checking " + header.Name) 49 size, ok := headerSizes[header.Name] 50 Expect(ok).To(BeTrue()) 51 Expect(size).To(Equal(header.Size)) 52 } 53 54 Expect(headers).To(Equal(2)) 55 }) 56 57 When("the build does not exist", func() { 58 It("returns nil", func() { 59 data, err := mp.PackageMetadata("fake_missing_build") 60 Expect(err).NotTo(HaveOccurred()) 61 Expect(data).To(BeNil()) 62 }) 63 }) 64 65 When("the build is not a directory", func() { 66 It("returns an error", func() { 67 _, err := mp.PackageMetadata("normal_archive.tar.gz") 68 Expect(err).To(MatchError("could not stat path: stat testdata/normal_archive.tar.gz/release: not a directory")) 69 }) 70 }) 71 })