github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/actor/pushaction/push_state_test.go (about) 1 package pushaction_test 2 3 import ( 4 "errors" 5 "os" 6 7 "code.cloudfoundry.org/cli/actor/actionerror" 8 . "code.cloudfoundry.org/cli/actor/pushaction" 9 "code.cloudfoundry.org/cli/actor/pushaction/pushactionfakes" 10 "code.cloudfoundry.org/cli/actor/sharedaction" 11 "code.cloudfoundry.org/cli/actor/v3action" 12 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 . "github.com/onsi/gomega/gstruct" 16 ) 17 18 var _ = Describe("Push State", func() { 19 var ( 20 actor *Actor 21 fakeV3Actor *pushactionfakes.FakeV3Actor 22 fakeSharedActor *pushactionfakes.FakeSharedActor 23 24 pwd string 25 ) 26 27 BeforeEach(func() { 28 actor, _, fakeV3Actor, fakeSharedActor = getTestPushActor() 29 }) 30 31 Describe("Conceptualize", func() { 32 var ( 33 settings CommandLineSettings 34 spaceGUID string 35 36 states []PushState 37 warnings Warnings 38 executeErr error 39 ) 40 41 BeforeEach(func() { 42 var err error 43 pwd, err = os.Getwd() 44 Expect(err).ToNot(HaveOccurred()) 45 settings = CommandLineSettings{ 46 Name: "some-app-name", 47 CurrentDirectory: pwd, 48 } 49 spaceGUID = "some-space-guid" 50 }) 51 52 JustBeforeEach(func() { 53 states, warnings, executeErr = actor.Conceptualize(settings, spaceGUID) 54 }) 55 56 Describe("application", func() { 57 When("the application exists", func() { 58 var app v3action.Application 59 60 BeforeEach(func() { 61 app = v3action.Application{ 62 GUID: "some-app-guid", 63 Name: "some-app-name", 64 } 65 66 fakeV3Actor.GetApplicationByNameAndSpaceReturns(app, v3action.Warnings{"some-app-warning"}, nil) 67 }) 68 69 It("uses the found app in the application state", func() { 70 Expect(executeErr).ToNot(HaveOccurred()) 71 Expect(warnings).To(ConsistOf("some-app-warning")) 72 Expect(states).To(HaveLen(1)) 73 74 Expect(states[0]).To(MatchFields(IgnoreExtras, 75 Fields{ 76 "Application": Equal(app), 77 "SpaceGUID": Equal(spaceGUID), 78 })) 79 80 Expect(fakeV3Actor.GetApplicationByNameAndSpaceCallCount()).To(Equal(1)) 81 passedName, passedSpaceGUID := fakeV3Actor.GetApplicationByNameAndSpaceArgsForCall(0) 82 Expect(passedName).To(Equal("some-app-name")) 83 Expect(passedSpaceGUID).To(Equal(spaceGUID)) 84 }) 85 }) 86 87 When("the application does not exist", func() { 88 BeforeEach(func() { 89 fakeV3Actor.GetApplicationByNameAndSpaceReturns(v3action.Application{}, v3action.Warnings{"some-app-warning"}, actionerror.ApplicationNotFoundError{}) 90 }) 91 92 It("creates a new app in the application state", func() { 93 Expect(executeErr).ToNot(HaveOccurred()) 94 Expect(warnings).To(ConsistOf("some-app-warning")) 95 Expect(states).To(HaveLen(1)) 96 97 Expect(states[0]).To(MatchFields(IgnoreExtras, 98 Fields{ 99 "Application": Equal(v3action.Application{ 100 Name: "some-app-name", 101 }), 102 "SpaceGUID": Equal(spaceGUID), 103 })) 104 }) 105 }) 106 107 When("the application lookup errors", func() { 108 var expectedErr error 109 110 BeforeEach(func() { 111 expectedErr = errors.New("some-error") 112 fakeV3Actor.GetApplicationByNameAndSpaceReturns(v3action.Application{}, v3action.Warnings{"some-app-warning"}, expectedErr) 113 }) 114 115 It("translates command line settings into a single push state", func() { 116 Expect(executeErr).To(MatchError(expectedErr)) 117 Expect(warnings).To(ConsistOf("some-app-warning")) 118 }) 119 }) 120 }) 121 122 Describe("bits path", func() { 123 When("no app path is provided in the command line settings", func() { 124 It("sets the bits path to the current directory in the settings", func() { 125 Expect(states[0].BitsPath).To(Equal(pwd)) 126 }) 127 }) 128 129 When("an app path is provided in the command line settings", func() { 130 BeforeEach(func() { 131 settings.ProvidedAppPath = "my-app-path" 132 }) 133 134 It("sets the bits path to the provided app path", func() { 135 Expect(states[0].BitsPath).To(Equal("my-app-path")) 136 }) 137 }) 138 }) 139 140 Describe("all resources", func() { 141 When("the app resources are given as a directory", func() { 142 var resources []sharedaction.Resource 143 144 When("gathering the resources is successful", func() { 145 146 BeforeEach(func() { 147 resources = []sharedaction.Resource{ 148 { 149 Filename: "fake-app-file", 150 }, 151 } 152 fakeSharedActor.GatherDirectoryResourcesReturns(resources, nil) 153 }) 154 155 It("adds the gathered resources to the push state", func() { 156 Expect(fakeSharedActor.GatherDirectoryResourcesCallCount()).To(Equal(1)) 157 Expect(fakeSharedActor.GatherDirectoryResourcesArgsForCall(0)).To(Equal(pwd)) 158 Expect(states[0].AllResources).To(Equal(resources)) 159 }) 160 }) 161 162 When("gathering the resources errors", func() { 163 BeforeEach(func() { 164 fakeSharedActor.GatherDirectoryResourcesReturns(nil, errors.New("kaboom")) 165 }) 166 167 It("returns the error", func() { 168 Expect(executeErr).To(MatchError("kaboom")) 169 }) 170 }) 171 }) 172 }) 173 }) 174 })