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