github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/actor/v7pushaction/update_web_process_for_application_test.go (about) 1 package v7pushaction_test 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/v7action" 5 . "code.cloudfoundry.org/cli/actor/v7pushaction" 6 "code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 8 "code.cloudfoundry.org/cli/types" 9 "errors" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/gstruct" 13 ) 14 15 var _ = Describe("UpdateWebProcessForApplication", func() { 16 var ( 17 actor *Actor 18 fakeV7Actor *v7pushactionfakes.FakeV7Actor 19 20 paramPlan PushPlan 21 22 warnings Warnings 23 executeErr error 24 25 events []Event 26 ) 27 28 BeforeEach(func() { 29 actor, _, fakeV7Actor, _ = getTestPushActor() 30 31 paramPlan = PushPlan{ 32 Application: v7action.Application{ 33 GUID: "some-app-guid", 34 }, 35 } 36 }) 37 38 JustBeforeEach(func() { 39 events = EventFollower(func(eventStream chan<- Event) { 40 _, warnings, executeErr = actor.UpdateWebProcessForApplication(paramPlan, eventStream, nil) 41 }) 42 }) 43 44 When("process configuration is provided", func() { 45 var startCommand types.FilteredString 46 47 BeforeEach(func() { 48 paramPlan.UpdateWebProcessNeedsUpdate = true 49 50 startCommand = types.FilteredString{IsSet: true, Value: "some-start-command"} 51 paramPlan.UpdateWebProcess = v7action.Process{ 52 Command: startCommand, 53 } 54 }) 55 56 When("the update is successful", func() { 57 BeforeEach(func() { 58 paramPlan.Application.GUID = "some-app-guid" 59 60 fakeV7Actor.UpdateApplicationReturns( 61 v7action.Application{ 62 Name: "some-app", 63 GUID: paramPlan.Application.GUID, 64 }, 65 v7action.Warnings{"some-app-update-warnings"}, 66 nil) 67 68 fakeV7Actor.UpdateProcessByTypeAndApplicationReturns(v7action.Warnings{"health-check-warnings"}, nil) 69 }) 70 71 It("sets the process config and returns warnings", func() { 72 Expect(executeErr).ToNot(HaveOccurred()) 73 Expect(warnings).To(ConsistOf("health-check-warnings")) 74 Expect(events).To(ConsistOf(SetProcessConfiguration, SetProcessConfigurationComplete)) 75 76 Expect(fakeV7Actor.UpdateProcessByTypeAndApplicationCallCount()).To(Equal(1)) 77 passedProcessType, passedAppGUID, passedProcess := fakeV7Actor.UpdateProcessByTypeAndApplicationArgsForCall(0) 78 Expect(passedProcessType).To(Equal(constant.ProcessTypeWeb)) 79 Expect(passedAppGUID).To(Equal("some-app-guid")) 80 Expect(passedProcess).To(MatchFields(IgnoreExtras, 81 Fields{ 82 "Command": Equal(startCommand), 83 })) 84 }) 85 }) 86 87 When("the update errors", func() { 88 var expectedErr error 89 90 BeforeEach(func() { 91 expectedErr = errors.New("nopes") 92 fakeV7Actor.UpdateProcessByTypeAndApplicationReturns(v7action.Warnings{"health-check-warnings"}, expectedErr) 93 }) 94 95 It("returns warnings and an error", func() { 96 Expect(executeErr).To(MatchError(expectedErr)) 97 Expect(warnings).To(ConsistOf("health-check-warnings")) 98 Expect(events).To(ConsistOf(SetProcessConfiguration)) 99 }) 100 }) 101 }) 102 103 When("process configuration is not provided", func() { 104 It("should not set the configuration", func() { 105 Expect(events).To(BeEmpty()) 106 Expect(executeErr).ToNot(HaveOccurred()) 107 Expect(fakeV7Actor.UpdateProcessByTypeAndApplicationCallCount()).To(Equal(0)) 108 }) 109 }) 110 })