github.com/sleungcy-sap/cli@v7.1.0+incompatible/actor/v3action/process_instance_test.go (about) 1 package v3action_test 2 3 import ( 4 "errors" 5 "time" 6 7 "code.cloudfoundry.org/cli/actor/actionerror" 8 . "code.cloudfoundry.org/cli/actor/v3action" 9 "code.cloudfoundry.org/cli/actor/v3action/v3actionfakes" 10 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 11 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 12 "code.cloudfoundry.org/cli/resources" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 ) 16 17 var _ = Describe("instance actions", func() { 18 var ( 19 actor *Actor 20 fakeCloudControllerClient *v3actionfakes.FakeCloudControllerClient 21 ) 22 23 BeforeEach(func() { 24 fakeCloudControllerClient = new(v3actionfakes.FakeCloudControllerClient) 25 actor = NewActor(fakeCloudControllerClient, nil, nil, nil) 26 }) 27 28 Describe("Instance", func() { 29 Describe("StartTime", func() { 30 It("returns the time that the instance started", func() { 31 uptime, err := time.ParseDuration("86400s") 32 Expect(err).ToNot(HaveOccurred()) 33 instance := ProcessInstance{Uptime: uptime} 34 Expect(instance.StartTime()).To(BeTemporally("~", time.Now().Add(-24*time.Hour), 10*time.Second)) 35 }) 36 }) 37 }) 38 39 Describe("DeleteInstanceByApplicationNameSpaceProcessTypeAndIndex", func() { 40 var ( 41 executeErr error 42 warnings Warnings 43 ) 44 45 JustBeforeEach(func() { 46 warnings, executeErr = actor.DeleteInstanceByApplicationNameSpaceProcessTypeAndIndex("some-app-name", "some-space-guid", "some-process-type", 666) 47 }) 48 49 When("getting the application returns an error", func() { 50 BeforeEach(func() { 51 fakeCloudControllerClient.GetApplicationsReturns([]resources.Application{}, ccv3.Warnings{"some-get-app-warning"}, errors.New("some-get-app-error")) 52 }) 53 54 It("returns all warnings and the error", func() { 55 Expect(executeErr).To(MatchError("some-get-app-error")) 56 Expect(warnings).To(ConsistOf("some-get-app-warning")) 57 }) 58 }) 59 60 When("getting the application succeeds", func() { 61 BeforeEach(func() { 62 fakeCloudControllerClient.GetApplicationsReturns([]resources.Application{{GUID: "some-app-guid"}}, ccv3.Warnings{"some-get-app-warning"}, nil) 63 }) 64 65 When("deleting the instance returns ProcessNotFoundError", func() { 66 BeforeEach(func() { 67 fakeCloudControllerClient.DeleteApplicationProcessInstanceReturns(ccv3.Warnings{"some-delete-warning"}, ccerror.ProcessNotFoundError{}) 68 }) 69 70 It("returns all warnings and the ProcessNotFoundError error", func() { 71 Expect(executeErr).To(Equal(actionerror.ProcessNotFoundError{ProcessType: "some-process-type"})) 72 Expect(warnings).To(ConsistOf("some-get-app-warning", "some-delete-warning")) 73 }) 74 }) 75 76 When("deleting the instance returns InstanceNotFoundError", func() { 77 BeforeEach(func() { 78 fakeCloudControllerClient.DeleteApplicationProcessInstanceReturns(ccv3.Warnings{"some-delete-warning"}, ccerror.InstanceNotFoundError{}) 79 }) 80 81 It("returns all warnings and the ProcessInstanceNotFoundError error", func() { 82 Expect(executeErr).To(Equal(actionerror.ProcessInstanceNotFoundError{ProcessType: "some-process-type", InstanceIndex: 666})) 83 Expect(warnings).To(ConsistOf("some-get-app-warning", "some-delete-warning")) 84 }) 85 }) 86 87 When("deleting the instance returns other error", func() { 88 BeforeEach(func() { 89 fakeCloudControllerClient.DeleteApplicationProcessInstanceReturns(ccv3.Warnings{"some-delete-warning"}, errors.New("some-delete-error")) 90 }) 91 92 It("returns all warnings and the error", func() { 93 Expect(executeErr).To(MatchError("some-delete-error")) 94 Expect(warnings).To(ConsistOf("some-get-app-warning", "some-delete-warning")) 95 }) 96 }) 97 98 When("deleting the instance succeeds", func() { 99 BeforeEach(func() { 100 fakeCloudControllerClient.DeleteApplicationProcessInstanceReturns(ccv3.Warnings{"some-delete-warning"}, nil) 101 }) 102 103 It("returns all warnings and no error", func() { 104 Expect(executeErr).ToNot(HaveOccurred()) 105 Expect(warnings).To(ConsistOf("some-get-app-warning", "some-delete-warning")) 106 107 Expect(fakeCloudControllerClient.GetApplicationsCallCount()).To(Equal(1)) 108 Expect(fakeCloudControllerClient.GetApplicationsArgsForCall(0)).To(ConsistOf( 109 ccv3.Query{Key: ccv3.NameFilter, Values: []string{"some-app-name"}}, 110 ccv3.Query{Key: ccv3.SpaceGUIDFilter, Values: []string{"some-space-guid"}}, 111 )) 112 113 Expect(fakeCloudControllerClient.DeleteApplicationProcessInstanceCallCount()).To(Equal(1)) 114 appGUID, processType, instanceIndex := fakeCloudControllerClient.DeleteApplicationProcessInstanceArgsForCall(0) 115 Expect(appGUID).To(Equal("some-app-guid")) 116 Expect(processType).To(Equal("some-process-type")) 117 Expect(instanceIndex).To(Equal(666)) 118 }) 119 }) 120 }) 121 }) 122 })