github.com/sap/cf-mta-plugin@v2.6.3+incompatible/util/archive_handler_test.go (about)

     1  package util_test
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/cloudfoundry-incubator/multiapps-cli-plugin/util"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("ArchiveHandler", func() {
    13  	Describe("GetMtaDescriptorFromArchive", func() {
    14  		var mtaArchiveFilePath, _ = filepath.Abs("../test_resources/commands/mtaArchive.mtar")
    15  		Context("with valid mta archive", func() {
    16  			It("should extract and return the id from deployment descriptor", func() {
    17  				descriptor, err := util.GetMtaDescriptorFromArchive(mtaArchiveFilePath)
    18  				Expect(err).To(BeZero())
    19  				Expect(descriptor.ID).To(Equal("test"))
    20  			})
    21  		})
    22  		Context("with valid mta archive and no deployment descriptor provided", func() {
    23  			It("should return error", func() {
    24  				mtaArchiveFilePath, _ = filepath.Abs("../test_resources/util/mtaArchiveNoDescriptor.mtar")
    25  				_, err := util.GetMtaDescriptorFromArchive(mtaArchiveFilePath)
    26  				Expect(err).To(MatchError("Could not get a valid MTA descriptor from archive"))
    27  			})
    28  		})
    29  
    30  		Context("with invalid mta archive", func() {
    31  			BeforeEach(func() {
    32  				os.Create("test.mtar")
    33  				mtaArchiveFilePath, _ = filepath.Abs("test.mtar")
    34  			})
    35  			It("should return error for not a valid zip archive", func() {
    36  				_, err := util.GetMtaDescriptorFromArchive(mtaArchiveFilePath)
    37  				Expect(err).To(MatchError("zip: not a valid zip file"))
    38  			})
    39  			AfterEach(func() {
    40  				os.Remove(mtaArchiveFilePath)
    41  			})
    42  		})
    43  	})
    44  })