github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v7action/event_test.go (about) 1 package v7action_test 2 3 import ( 4 "errors" 5 6 . "code.cloudfoundry.org/cli/actor/v7action" 7 "code.cloudfoundry.org/cli/actor/v7action/v7actionfakes" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("Event Actions", func() { 14 var ( 15 actor *Actor 16 fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient 17 ) 18 19 BeforeEach(func() { 20 actor, fakeCloudControllerClient, _, _, _, _ = NewTestActor() 21 }) 22 23 Describe("GetRecentEventsForApp", func() { 24 var ( 25 appName string 26 spaceGUID string 27 events []Event 28 warnings Warnings 29 err error 30 ) 31 32 BeforeEach(func() { 33 appName = "some-app-name" 34 spaceGUID = "some-space-guid" 35 }) 36 37 JustBeforeEach(func() { 38 events, warnings, err = actor.GetRecentEventsByApplicationNameAndSpace(appName, spaceGUID) 39 }) 40 41 When("getting the app succeeds", func() { 42 BeforeEach(func() { 43 apps := []ccv3.Application{ 44 {GUID: "some-app-guid"}, 45 } 46 47 ccWarnings := ccv3.Warnings{ 48 "some-app-warnings", 49 } 50 51 fakeCloudControllerClient.GetApplicationsReturns( 52 apps, 53 ccWarnings, 54 nil, 55 ) 56 }) 57 58 When("the cc client returns the list of events", func() { 59 BeforeEach(func() { 60 ccEvents := []ccv3.Event{ 61 {GUID: "event-1", Type: "audit.app.wow", Data: map[string]interface{}{"index": "17"}}, 62 {GUID: "event-2", Type: "audit.app.cool", Data: map[string]interface{}{"unimportant_key": "23"}}, 63 } 64 65 ccWarnings := ccv3.Warnings{ 66 "some-event-warnings", 67 } 68 69 fakeCloudControllerClient.GetEventsReturns( 70 ccEvents, 71 ccWarnings, 72 nil, 73 ) 74 }) 75 76 It("returns the events and warnings", func() { 77 Expect(events).To(Equal([]Event{ 78 {GUID: "event-1", Type: "audit.app.wow", Description: "index: 17"}, 79 {GUID: "event-2", Type: "audit.app.cool", Description: ""}, 80 })) 81 Expect(warnings).To(ConsistOf("some-app-warnings", "some-event-warnings")) 82 Expect(err).NotTo(HaveOccurred()) 83 }) 84 }) 85 86 When("the cc client returns an error", func() { 87 BeforeEach(func() { 88 ccWarnings := ccv3.Warnings{ 89 "some-event-warnings", 90 } 91 92 fakeCloudControllerClient.GetEventsReturns( 93 nil, 94 ccWarnings, 95 errors.New("failed to get events"), 96 ) 97 }) 98 99 It("returns the err and warnings", func() { 100 Expect(warnings).To(ConsistOf("some-app-warnings", "some-event-warnings")) 101 Expect(err).To(MatchError("failed to get events")) 102 }) 103 }) 104 }) 105 106 When("getting the app fails", func() { 107 BeforeEach(func() { 108 ccWarnings := ccv3.Warnings{ 109 "some-app-warnings", 110 } 111 112 fakeCloudControllerClient.GetApplicationsReturns( 113 nil, 114 ccWarnings, 115 errors.New("failed to get app"), 116 ) 117 }) 118 119 It("returns the err and warnings", func() { 120 Expect(warnings).To(ConsistOf("some-app-warnings")) 121 Expect(err).To(MatchError("failed to get app")) 122 }) 123 }) 124 }) 125 })