github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/buildpacks_command_test.go (about) 1 package v7_test 2 3 import ( 4 "errors" 5 6 "github.com/LukasHeimann/cloudfoundrycli/v8/resources" 7 "github.com/LukasHeimann/cloudfoundrycli/v8/types" 8 9 "github.com/LukasHeimann/cloudfoundrycli/v8/actor/actionerror" 10 "github.com/LukasHeimann/cloudfoundrycli/v8/actor/v7action" 11 "github.com/LukasHeimann/cloudfoundrycli/v8/command/commandfakes" 12 . "github.com/LukasHeimann/cloudfoundrycli/v8/command/v7" 13 "github.com/LukasHeimann/cloudfoundrycli/v8/command/v7/v7fakes" 14 "github.com/LukasHeimann/cloudfoundrycli/v8/util/configv3" 15 "github.com/LukasHeimann/cloudfoundrycli/v8/util/ui" 16 17 . "github.com/onsi/ginkgo" 18 . "github.com/onsi/gomega" 19 . "github.com/onsi/gomega/gbytes" 20 ) 21 22 var _ = Describe("buildpacks Command", func() { 23 var ( 24 cmd BuildpacksCommand 25 testUI *ui.UI 26 fakeConfig *commandfakes.FakeConfig 27 fakeSharedActor *commandfakes.FakeSharedActor 28 fakeActor *v7fakes.FakeActor 29 executeErr error 30 args []string 31 binaryName string 32 ) 33 34 BeforeEach(func() { 35 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 36 fakeConfig = new(commandfakes.FakeConfig) 37 fakeSharedActor = new(commandfakes.FakeSharedActor) 38 fakeActor = new(v7fakes.FakeActor) 39 args = nil 40 41 cmd = BuildpacksCommand{ 42 BaseCommand: BaseCommand{ 43 UI: testUI, 44 Config: fakeConfig, 45 SharedActor: fakeSharedActor, 46 Actor: fakeActor, 47 }, 48 } 49 50 binaryName = "faceman" 51 fakeConfig.BinaryNameReturns(binaryName) 52 }) 53 54 JustBeforeEach(func() { 55 executeErr = cmd.Execute(args) 56 }) 57 58 When("the environment is not set up correctly", func() { 59 BeforeEach(func() { 60 fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) 61 }) 62 63 It("returns an error", func() { 64 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 65 66 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 67 checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 68 Expect(checkTargetedOrg).To(BeFalse()) 69 Expect(checkTargetedSpace).To(BeFalse()) 70 }) 71 }) 72 73 When("the environment is setup correctly", func() { 74 BeforeEach(func() { 75 fakeActor.GetCurrentUserReturns(configv3.User{Name: "apple"}, nil) 76 }) 77 78 It("should print text indicating its runnning", func() { 79 Expect(executeErr).NotTo(HaveOccurred()) 80 Expect(testUI.Out).To(Say(`Getting buildpacks as apple\.\.\.`)) 81 }) 82 83 When("the --labels flag is used", func() { 84 BeforeEach(func() { 85 cmd.Labels = "some-label-selector" 86 }) 87 88 It("passes the label selector to the actor", func() { 89 labelSelector := fakeActor.GetBuildpacksArgsForCall(0) 90 Expect(labelSelector).To(Equal("some-label-selector")) 91 }) 92 }) 93 94 When("getting buildpacks fails", func() { 95 BeforeEach(func() { 96 fakeActor.GetBuildpacksReturns(nil, v7action.Warnings{"some-warning-1", "some-warning-2"}, 97 errors.New("some-error")) 98 }) 99 100 It("prints warnings and returns error", func() { 101 Expect(executeErr).To(MatchError("some-error")) 102 103 Expect(testUI.Err).To(Say("some-warning-1")) 104 Expect(testUI.Err).To(Say("some-warning-2")) 105 }) 106 }) 107 108 When("getting buildpacks succeeds", func() { 109 When("buildpacks exist", func() { 110 BeforeEach(func() { 111 buildpacks := []resources.Buildpack{ 112 { 113 Name: "buildpack-1", 114 Position: types.NullInt{Value: 1, IsSet: true}, 115 Enabled: types.NullBool{Value: true, IsSet: true}, 116 Locked: types.NullBool{Value: false, IsSet: true}, 117 Filename: "buildpack-1.file", 118 Stack: "buildpack-1-stack", 119 }, 120 121 { 122 Name: "buildpack-2", 123 Position: types.NullInt{Value: 2, IsSet: true}, 124 Enabled: types.NullBool{Value: false, IsSet: true}, 125 Locked: types.NullBool{Value: true, IsSet: true}, 126 Filename: "buildpack-2.file", 127 Stack: "", 128 }, 129 } 130 fakeActor.GetBuildpacksReturns(buildpacks, v7action.Warnings{"some-warning-1", "some-warning-2"}, nil) 131 }) 132 It("prints a table of buildpacks", func() { 133 Expect(executeErr).NotTo(HaveOccurred()) 134 Expect(testUI.Err).To(Say("some-warning-1")) 135 Expect(testUI.Err).To(Say("some-warning-2")) 136 Expect(testUI.Out).To(Say(`position\s+name\s+stack\s+enabled\s+locked\s+filename`)) 137 Expect(testUI.Out).To(Say(`1\s+buildpack-1\s+buildpack-1-stack\s+true\s+false\s+buildpack-1.file`)) 138 Expect(testUI.Out).To(Say(`2\s+buildpack-2\s+false\s+true\s+buildpack-2.file`)) 139 }) 140 }) 141 When("there are no buildpacks", func() { 142 BeforeEach(func() { 143 buildpacks := []resources.Buildpack{} 144 fakeActor.GetBuildpacksReturns(buildpacks, v7action.Warnings{"some-warning-1", "some-warning-2"}, nil) 145 }) 146 It("prints a table of buildpacks", func() { 147 Expect(executeErr).NotTo(HaveOccurred()) 148 Expect(testUI.Err).To(Say("some-warning-1")) 149 Expect(testUI.Err).To(Say("some-warning-2")) 150 Expect(testUI.Out).To(Say("No buildpacks found")) 151 }) 152 }) 153 }) 154 }) 155 })