github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/global/create_buildpack_command_test.go (about)

     1  package global
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  
     7  	"code.cloudfoundry.org/cli/integration/helpers"
     8  
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("create-buildpack command", func() {
    17  	var (
    18  		buildpackName string
    19  		stacks        []string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		helpers.LoginCF()
    24  		buildpackName = helpers.NewBuildpack()
    25  	})
    26  
    27  	Context("when creating a new buildpack", func() {
    28  		Context("without stack association", func() {
    29  			It("creates the new buildpack", func() {
    30  				helpers.BuildpackWithStack(func(buildpackPath string) {
    31  					session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
    32  					Eventually(session).Should(Exit(0))
    33  				}, "")
    34  
    35  				session := helpers.CF("buildpacks")
    36  				Eventually(session).Should(Exit(0))
    37  				Expect(session.Out).To(Say(buildpackName))
    38  			})
    39  		})
    40  
    41  		Context("with stack association", func() {
    42  			BeforeEach(func() {
    43  				helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV3)
    44  				stacks = helpers.FetchStacks()
    45  			})
    46  
    47  			It("creates the new buildpack and assigns its stack", func() {
    48  				helpers.BuildpackWithStack(func(buildpackPath string) {
    49  					session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
    50  					Eventually(session).Should(Exit(0))
    51  				}, stacks[0])
    52  
    53  				session := helpers.CF("buildpacks")
    54  				Eventually(session).Should(Exit(0))
    55  				Expect(session.Out).To(Say(buildpackName+".*%s.*1", stacks[0]))
    56  			})
    57  		})
    58  	})
    59  
    60  	Context("when creating a buildpack with no stack that already exists", func() {
    61  		BeforeEach(func() {
    62  			helpers.BuildpackWithStack(func(buildpackPath string) {
    63  				session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
    64  				Eventually(session).Should(Exit(0))
    65  			}, "")
    66  		})
    67  
    68  		It("issues a warning and exits 0", func() {
    69  			helpers.BuildpackWithStack(func(buildpackPath string) {
    70  				session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
    71  				Eventually(session).Should(Exit(0))
    72  				Eventually(session.Out).Should(Say("Buildpack %s already exists", buildpackName))
    73  			}, "")
    74  		})
    75  	})
    76  
    77  	Context("when creating a buildpack/stack that already exists", func() {
    78  		BeforeEach(func() {
    79  			stacks = helpers.FetchStacks()
    80  
    81  			helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV3)
    82  			helpers.BuildpackWithStack(func(buildpackPath string) {
    83  				session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
    84  				Eventually(session).Should(Exit(0))
    85  			}, stacks[0])
    86  		})
    87  
    88  		It("issues a warning and exits 0", func() {
    89  			helpers.BuildpackWithStack(func(buildpackPath string) {
    90  				session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
    91  				Eventually(session).Should(Exit(0))
    92  				Eventually(session.Out).Should(Say("The buildpack name " + buildpackName + " is already in use for the stack " + stacks[0]))
    93  			}, stacks[0])
    94  		})
    95  	})
    96  
    97  	Context("when the wrong data type is provided as the position argument", func() {
    98  		var (
    99  			filename string
   100  		)
   101  
   102  		BeforeEach(func() {
   103  			// The args take a filepath. Creating a real file will avoid the file
   104  			// does not exist error, and trigger the correct error case we are
   105  			// testing.
   106  			f, err := ioutil.TempFile("", "create-buildpack-invalid")
   107  			Expect(err).NotTo(HaveOccurred())
   108  			f.Close()
   109  
   110  			filename = f.Name()
   111  		})
   112  
   113  		AfterEach(func() {
   114  			err := os.Remove(filename)
   115  			Expect(err).NotTo(HaveOccurred())
   116  		})
   117  
   118  		It("outputs an error message to the user, provides help text, and exits 1", func() {
   119  			session := helpers.CF("create-buildpack", buildpackName, filename, "not-an-integer")
   120  			Eventually(session.Err).Should(Say("Incorrect usage: Value for POSITION must be integer"))
   121  			Eventually(session).Should(Say("cf create-buildpack BUILDPACK PATH POSITION")) // help
   122  			Eventually(session).Should(Exit(1))
   123  		})
   124  	})
   125  
   126  	Context("when a nonexistent file is provided", func() {
   127  		It("outputs an error message to the user and exits 1", func() {
   128  			session := helpers.CF("create-buildpack", buildpackName, "some-bogus-file", "1")
   129  			Eventually(session.Err).Should(Say("Incorrect Usage: The specified path 'some-bogus-file' does not exist."))
   130  			Eventually(session).Should(Exit(1))
   131  		})
   132  	})
   133  
   134  	Context("when a URL is provided as the buildpack", func() {
   135  		It("outputs an error message to the user, provides help text, and exits 1", func() {
   136  			session := helpers.CF("create-buildpack", buildpackName, "https://example.com/bogus.tgz", "1")
   137  			Eventually(session).Should(Say("Failed to create a local temporary zip file for the buildpack"))
   138  			Eventually(session).Should(Say("FAILED"))
   139  			Eventually(session).Should(Say("Couldn't write zip file: zip: not a valid zip file"))
   140  			Eventually(session).Should(Exit(1))
   141  		})
   142  	})
   143  })