github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/commands/buildpack/buildpacks_test.go (about) 1 package buildpack_test 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/api/apifakes" 5 "code.cloudfoundry.org/cli/cf/commandregistry" 6 "code.cloudfoundry.org/cli/cf/flags" 7 "code.cloudfoundry.org/cli/cf/models" 8 "code.cloudfoundry.org/cli/cf/requirements" 9 "code.cloudfoundry.org/cli/cf/requirements/requirementsfakes" 10 testcmd "code.cloudfoundry.org/cli/util/testhelpers/commands" 11 testterm "code.cloudfoundry.org/cli/util/testhelpers/terminal" 12 13 "code.cloudfoundry.org/cli/cf/commands/buildpack" 14 . "code.cloudfoundry.org/cli/util/testhelpers/matchers" 15 . "github.com/onsi/ginkgo" 16 . "github.com/onsi/gomega" 17 ) 18 19 var _ = Describe("ListBuildpacks", func() { 20 var ( 21 ui *testterm.FakeUI 22 buildpackRepo *apifakes.OldFakeBuildpackRepository 23 requirementsFactory *requirementsfakes.FakeFactory 24 deps commandregistry.Dependency 25 ) 26 27 updateCommandDependency := func(pluginCall bool) { 28 deps.UI = ui 29 deps.RepoLocator = deps.RepoLocator.SetBuildpackRepository(buildpackRepo) 30 commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("buildpacks").SetDependency(deps, pluginCall)) 31 } 32 33 BeforeEach(func() { 34 ui = &testterm.FakeUI{} 35 buildpackRepo = new(apifakes.OldFakeBuildpackRepository) 36 requirementsFactory = new(requirementsfakes.FakeFactory) 37 }) 38 39 runCommand := func(args ...string) bool { 40 return testcmd.RunCLICommand("buildpacks", args, requirementsFactory, updateCommandDependency, false, ui) 41 } 42 43 Context("when arguments are provided", func() { 44 var cmd commandregistry.Command 45 var flagContext flags.FlagContext 46 47 BeforeEach(func() { 48 cmd = &buildpack.ListBuildpacks{} 49 cmd.SetDependency(deps, false) 50 flagContext = flags.NewFlagContext(cmd.MetaData().Flags) 51 }) 52 53 It("should fail with usage", func() { 54 flagContext.Parse("blahblah") 55 56 reqs, err := cmd.Requirements(requirementsFactory, flagContext) 57 Expect(err).NotTo(HaveOccurred()) 58 59 err = testcmd.RunRequirements(reqs) 60 Expect(err).To(HaveOccurred()) 61 Expect(err.Error()).To(ContainSubstring("Incorrect Usage")) 62 Expect(err.Error()).To(ContainSubstring("No argument required")) 63 }) 64 }) 65 66 It("fails requirements when login fails", func() { 67 requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"}) 68 Expect(runCommand()).To(BeFalse()) 69 }) 70 71 Context("when logged in", func() { 72 BeforeEach(func() { 73 requirementsFactory.NewLoginRequirementReturns(requirements.Passing{}) 74 }) 75 76 It("lists buildpacks", func() { 77 p1 := 5 78 p2 := 10 79 p3 := 15 80 t := true 81 f := false 82 83 buildpackRepo.Buildpacks = []models.Buildpack{ 84 {Name: "Buildpack-1", Position: &p1, Enabled: &t, Locked: &f}, 85 {Name: "Buildpack-2", Position: &p2, Enabled: &f, Locked: &t}, 86 {Name: "Buildpack-3", Position: &p3, Enabled: &t, Locked: &f}, 87 } 88 89 runCommand() 90 91 Expect(ui.Outputs()).To(ContainSubstrings( 92 []string{"Getting buildpacks"}, 93 []string{"buildpack", "position", "enabled"}, 94 []string{"Buildpack-1", "5", "true", "false"}, 95 []string{"Buildpack-2", "10", "false", "true"}, 96 []string{"Buildpack-3", "15", "true", "false"}, 97 )) 98 }) 99 100 It("tells the user if no build packs exist", func() { 101 runCommand() 102 Expect(ui.Outputs()).To(ContainSubstrings( 103 []string{"Getting buildpacks"}, 104 []string{"No buildpacks found"}, 105 )) 106 }) 107 }) 108 109 })