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

     1  package global
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gbytes"
    10  	. "github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("delete-buildpack command", func() {
    14  	var (
    15  		buildpackName string
    16  		stacks        []string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		helpers.LoginCF()
    21  		buildpackName = helpers.NewBuildpack()
    22  	})
    23  
    24  	Context("when the environment is not setup correctly", func() {
    25  		XIt("fails with the appropriate errors", func() {
    26  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "delete-buildpack", "nonexistent-buildpack")
    27  		})
    28  	})
    29  
    30  	Context("when the buildpack name is not provided", func() {
    31  		It("displays an error and help", func() {
    32  			session := helpers.CF("delete-buildpack")
    33  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `BUILDPACK` was not provided"))
    34  			Eventually(session).Should(Say("USAGE"))
    35  			Eventually(session).Should(Exit(1))
    36  		})
    37  	})
    38  
    39  	Context("when the buildpack doesn't exist", func() {
    40  		It("displays a warning and exits 0", func() {
    41  			session := helpers.CF("delete-buildpack", "-f", "nonexistent-buildpack")
    42  			Eventually(session).Should(Say("Deleting buildpack nonexistent-buildpack"))
    43  			Eventually(session).Should(Say("OK"))
    44  			Eventually(session).Should(Say("Buildpack nonexistent-buildpack does not exist."))
    45  			Eventually(session).Should(Exit(0))
    46  		})
    47  	})
    48  
    49  	Context("there is exactly one buildpack with the specified name", func() {
    50  
    51  		BeforeEach(func() {
    52  			stacks = helpers.FetchStacks()
    53  			helpers.BuildpackWithStack(func(buildpackPath string) {
    54  				session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
    55  				Eventually(session).Should(Exit(0))
    56  			}, stacks[0])
    57  		})
    58  
    59  		Context("when the stack is specified", func() {
    60  			It("deletes the specified buildpack", func() {
    61  				session := helpers.CF("delete-buildpack", buildpackName, "-s", stacks[0], "-f")
    62  				Eventually(session).Should(Exit(0))
    63  				Eventually(session.Out).Should(Say("OK"))
    64  			})
    65  		})
    66  
    67  		Context("when the stack is not specified", func() {
    68  			It("deletes the specified buildpack", func() {
    69  				session := helpers.CF("delete-buildpack", buildpackName, "-f")
    70  				Eventually(session).Should(Exit(0))
    71  				Eventually(session.Out).Should(Say("OK"))
    72  			})
    73  		})
    74  	})
    75  
    76  	Context("there are two buildpacks with same name", func() {
    77  
    78  		BeforeEach(func() {
    79  			helpers.SkipIfVersionLessThan(ccversion.MinVersionBuildpackStackAssociationV3)
    80  			helpers.SkipIfOneStack()
    81  		})
    82  
    83  		Context("neither buildpack has a nil stack", func() {
    84  			BeforeEach(func() {
    85  				stacks = helpers.FetchStacks()
    86  
    87  				helpers.BuildpackWithStack(func(buildpackPath string) {
    88  					session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
    89  					Eventually(session).Should(Exit(0))
    90  				}, stacks[0])
    91  
    92  				helpers.BuildpackWithStack(func(buildpackPath string) {
    93  					session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
    94  					Eventually(session).Should(Exit(0))
    95  				}, stacks[1])
    96  			})
    97  
    98  			It("properly handles ambiguity", func() {
    99  				By("failing when no stack specified")
   100  
   101  				session := helpers.CF("delete-buildpack", buildpackName, "-f")
   102  				Eventually(session).Should(Exit(1))
   103  				Eventually(session.Out).Should(Say("FAILED"))
   104  
   105  				By("deleting the buildpack when the associated stack is specified")
   106  
   107  				session = helpers.CF("delete-buildpack", buildpackName, "-s", stacks[0], "-f")
   108  				Eventually(session).Should(Exit(0))
   109  				Eventually(session.Out).Should(Say("OK"))
   110  
   111  				session = helpers.CF("delete-buildpack", buildpackName, "-s", stacks[1], "-f")
   112  				Eventually(session).Should(Exit(0))
   113  				Eventually(session.Out).Should(Say("OK"))
   114  			})
   115  		})
   116  
   117  		Context("one buildpack has a nil stack", func() {
   118  
   119  			BeforeEach(func() {
   120  				stacks = helpers.FetchStacks()
   121  
   122  				helpers.BuildpackWithStack(func(buildpackPath string) {
   123  					session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
   124  					Eventually(session).Should(Exit(0))
   125  				}, stacks[0])
   126  
   127  				helpers.BuildpackWithStack(func(buildpackPath string) {
   128  					session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
   129  					Eventually(session).Should(Exit(0))
   130  				}, "")
   131  			})
   132  
   133  			It("properly handles ambiguity", func() {
   134  				By("deleting nil buildpack when no stack specified")
   135  				session := helpers.CF("delete-buildpack", buildpackName, "-f")
   136  				Eventually(session).Should(Exit(0))
   137  				Eventually(session.Out).Should(Say("OK"))
   138  
   139  				By("deleting the remaining buildpack when no stack is specified")
   140  				session = helpers.CF("delete-buildpack", buildpackName, "-f")
   141  				Eventually(session).Should(Exit(0))
   142  				Eventually(session.Out).Should(Say("OK"))
   143  			})
   144  		})
   145  	})
   146  
   147  	Context("when the -f flag not is provided", func() {
   148  		var buffer *Buffer
   149  
   150  		BeforeEach(func() {
   151  			buffer = NewBuffer()
   152  
   153  			helpers.BuildpackWithStack(func(buildpackPath string) {
   154  				session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "1")
   155  				Eventually(session).Should(Exit(0))
   156  			}, "")
   157  		})
   158  
   159  		Context("when the user enters 'y'", func() {
   160  			BeforeEach(func() {
   161  				buffer.Write([]byte("y\n"))
   162  			})
   163  
   164  			It("deletes the buildpack", func() {
   165  				session := helpers.CFWithStdin(buffer, "delete-buildpack", buildpackName)
   166  				Eventually(session).Should(Say("Deleting buildpack %s", buildpackName))
   167  				Eventually(session).Should(Say("OK"))
   168  				Eventually(session).Should(Exit(0))
   169  			})
   170  		})
   171  
   172  		Context("when the user enters 'n'", func() {
   173  			BeforeEach(func() {
   174  				buffer.Write([]byte("n\n"))
   175  			})
   176  
   177  			It("does not delete the buildpack", func() {
   178  				session := helpers.CFWithStdin(buffer, "delete-buildpack", buildpackName)
   179  				Eventually(session).Should(Say("Delete cancelled"))
   180  				Eventually(session).Should(Exit(0))
   181  
   182  				session = helpers.CF("buildpacks")
   183  				Eventually(session).Should(Say(buildpackName))
   184  				Eventually(session).Should(Exit(0))
   185  			})
   186  		})
   187  
   188  		Context("when the user enters the default input (hits return)", func() {
   189  			BeforeEach(func() {
   190  				buffer.Write([]byte("\n"))
   191  			})
   192  
   193  			It("does not delete the buildpack", func() {
   194  				session := helpers.CFWithStdin(buffer, "delete-buildpack", buildpackName)
   195  				Eventually(session).Should(Say("Delete cancelled"))
   196  				Eventually(session).Should(Exit(0))
   197  
   198  				session = helpers.CF("buildpacks")
   199  				Eventually(session).Should(Say(buildpackName))
   200  				Eventually(session).Should(Exit(0))
   201  			})
   202  		})
   203  	})
   204  
   205  	Context("when the -f flag is provided", func() {
   206  		It("deletes the org", func() {
   207  			session := helpers.CF("delete-buildpack", buildpackName, "-f")
   208  			Eventually(session).Should(Say("Deleting buildpack %s", buildpackName))
   209  			Eventually(session).Should(Say("OK"))
   210  			Eventually(session).Should(Exit(0))
   211  		})
   212  	})
   213  })