github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/actor/v3action/process_test.go (about) 1 package v3action_test 2 3 import ( 4 "errors" 5 6 . "github.com/liamawhite/cli-with-i18n/actor/v3action" 7 "github.com/liamawhite/cli-with-i18n/actor/v3action/v3actionfakes" 8 "github.com/liamawhite/cli-with-i18n/api/cloudcontroller/ccerror" 9 "github.com/liamawhite/cli-with-i18n/api/cloudcontroller/ccv3" 10 "github.com/liamawhite/cli-with-i18n/api/cloudcontroller/ccv3/constant" 11 "github.com/liamawhite/cli-with-i18n/types" 12 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 ) 16 17 var _ = Describe("Process Actions", func() { 18 var ( 19 actor *Actor 20 fakeCloudControllerClient *v3actionfakes.FakeCloudControllerClient 21 ) 22 23 BeforeEach(func() { 24 fakeCloudControllerClient = new(v3actionfakes.FakeCloudControllerClient) 25 actor = NewActor(nil, fakeCloudControllerClient, nil) 26 }) 27 28 Describe("ScaleProcessByApplication", func() { 29 var passedProcess Process 30 31 BeforeEach(func() { 32 passedProcess = Process{ 33 Type: constant.ProcessTypeWeb, 34 Instances: types.NullInt{Value: 2, IsSet: true}, 35 MemoryInMB: types.NullUint64{Value: 100, IsSet: true}, 36 DiskInMB: types.NullUint64{Value: 200, IsSet: true}, 37 } 38 }) 39 40 Context("when no errors are encountered scaling the application process", func() { 41 BeforeEach(func() { 42 fakeCloudControllerClient.CreateApplicationProcessScaleReturns( 43 ccv3.Warnings{"scale-process-warning"}, 44 nil) 45 }) 46 47 It("scales correct process", func() { 48 warnings, err := actor.ScaleProcessByApplication("some-app-guid", passedProcess) 49 50 Expect(err).ToNot(HaveOccurred()) 51 Expect(warnings).To(ConsistOf("scale-process-warning")) 52 53 Expect(fakeCloudControllerClient.CreateApplicationProcessScaleCallCount()).To(Equal(1)) 54 appGUIDArg, processArg := fakeCloudControllerClient.CreateApplicationProcessScaleArgsForCall(0) 55 Expect(appGUIDArg).To(Equal("some-app-guid")) 56 Expect(processArg).To(Equal(ccv3.Process{ 57 Type: constant.ProcessTypeWeb, 58 Instances: passedProcess.Instances, 59 MemoryInMB: passedProcess.MemoryInMB, 60 DiskInMB: passedProcess.DiskInMB, 61 })) 62 }) 63 }) 64 65 Context("when an error is encountered scaling the application process", func() { 66 var expectedErr error 67 68 BeforeEach(func() { 69 expectedErr = errors.New("scale process error") 70 fakeCloudControllerClient.CreateApplicationProcessScaleReturns( 71 ccv3.Warnings{"scale-process-warning"}, 72 expectedErr) 73 }) 74 75 It("returns the error and all warnings", func() { 76 warnings, err := actor.ScaleProcessByApplication("some-app-guid", passedProcess) 77 Expect(err).To(MatchError(expectedErr)) 78 Expect(warnings).To(ConsistOf("scale-process-warning")) 79 }) 80 }) 81 82 Context("when a ProcessNotFoundError error is encountered scaling the application process", func() { 83 BeforeEach(func() { 84 fakeCloudControllerClient.CreateApplicationProcessScaleReturns( 85 ccv3.Warnings{"scale-process-warning"}, 86 ccerror.ProcessNotFoundError{}, 87 ) 88 }) 89 90 It("returns the error and all warnings", func() { 91 warnings, err := actor.ScaleProcessByApplication("some-app-guid", passedProcess) 92 Expect(err).To(Equal(ProcessNotFoundError{ProcessType: constant.ProcessTypeWeb})) 93 Expect(warnings).To(ConsistOf("scale-process-warning")) 94 }) 95 }) 96 }) 97 })