@@ -64,18 +64,18 @@ func NewEventList(oc *exutil.CLI, namespace string) *EventList {
6464 return & EventList {* NewNamespacedResourceList (oc , "Event" , namespace )}
6565}
6666
67- // GetAll returns a []Event list with all existing events sorted by last occurrence
67+ // GetAll returns a []* Event list with all existing events sorted by last occurrence
6868// the first element will be the most recent one
69- func (el * EventList ) GetAll () ([]Event , error ) {
69+ func (el * EventList ) GetAll () ([]* Event , error ) {
7070 el .SortByLastTimestamp ()
7171 allEventResources , err := el .ResourceList .GetAll ()
7272 if err != nil {
7373 return nil , err
7474 }
75- allEvents := make ([]Event , 0 , len (allEventResources ))
75+ allEvents := make ([]* Event , 0 , len (allEventResources ))
7676
7777 for _ , eventRes := range allEventResources {
78- allEvents = append (allEvents , * NewEvent (el .oc , eventRes .namespace , eventRes .name ))
78+ allEvents = append (allEvents , NewEvent (el .oc , eventRes .namespace , eventRes .name ))
7979 }
8080 // We want the first element to be the more recent
8181 allEvents = reverseEventsList (allEvents )
@@ -100,11 +100,11 @@ func (el *EventList) GetLatest() (*Event, error) {
100100 return nil , nil
101101 }
102102
103- return & ( allEvents [0 ]) , nil
103+ return allEvents [0 ], nil
104104}
105105
106106// GetAllEventsSinceEvent returns all events that occurred since a given event (not included)
107- func (el * EventList ) GetAllEventsSinceEvent (sinceEvent * Event ) ([]Event , error ) {
107+ func (el * EventList ) GetAllEventsSinceEvent (sinceEvent * Event ) ([]* Event , error ) {
108108 allEvents , lerr := el .GetAll ()
109109 if lerr != nil {
110110 logger .Errorf ("Error getting events %s" , lerr )
@@ -115,7 +115,7 @@ func (el *EventList) GetAllEventsSinceEvent(sinceEvent *Event) ([]Event, error)
115115 return allEvents , nil
116116 }
117117
118- returnEvents := []Event {}
118+ returnEvents := []* Event {}
119119 for _ , event := range allEvents {
120120 if event .name == sinceEvent .name {
121121 break
@@ -127,7 +127,7 @@ func (el *EventList) GetAllEventsSinceEvent(sinceEvent *Event) ([]Event, error)
127127}
128128
129129// GetAllSince return a list of the events that happened since the provided duration
130- func (el * EventList ) GetAllSince (since time.Time ) ([]Event , error ) {
130+ func (el * EventList ) GetAllSince (since time.Time ) ([]* Event , error ) {
131131 // Remove log noise
132132 el .oc .NotShowInfo ()
133133 defer el .oc .SetShowInfo ()
@@ -138,7 +138,7 @@ func (el *EventList) GetAllSince(since time.Time) ([]Event, error) {
138138 return nil , lerr
139139 }
140140
141- returnEvents := []Event {}
141+ returnEvents := []* Event {}
142142 for _ , loopEvent := range allEvents {
143143 event := loopEvent // this is to make sure that we execute defer in all events, and not only in the last one
144144 // Remove log noise
@@ -162,7 +162,7 @@ func (el *EventList) GetAllSince(since time.Time) ([]Event, error) {
162162}
163163
164164// from https://github.com/golang/go/wiki/SliceTricks#reversing
165- func reverseEventsList (a []Event ) []Event {
165+ func reverseEventsList (a []* Event ) []* Event {
166166
167167 for i := len (a )/ 2 - 1 ; i >= 0 ; i -- {
168168 opp := len (a ) - 1 - i
@@ -202,14 +202,15 @@ type haveEventsSequenceMatcher struct {
202202func (matcher * haveEventsSequenceMatcher ) Match (actual interface {}) (success bool , err error ) {
203203
204204 logger .Infof ("Start verifying events sequence: %s" , matcher .sequence )
205- events , ok := actual .([]Event )
205+ events , ok := actual .([]* Event )
206206 if ! ok {
207- return false , fmt .Errorf ("HaveSequence matcher expects a slice of Events in test case %v" , g .CurrentSpecReport ().FullText ())
207+ return false , fmt .Errorf ("HaveSequence matcher expects a slice of []*Event in test case %v" , g .CurrentSpecReport ().FullText ())
208208 }
209209
210210 // To avoid too many "oc" executions we store the events information in a cached struct list with "lastTimestamp" and "reason" fields.
211211 tmpEvents := make ([]tmpEvent , len (events ))
212- for index , event := range events {
212+ for index , loopEvent := range events {
213+ event := loopEvent // this is to make sure that we execute defer in all events, and not only in the last one
213214 event .oc .NotShowInfo ()
214215 defer event .oc .SetShowInfo ()
215216
@@ -258,7 +259,7 @@ func (matcher *haveEventsSequenceMatcher) Match(actual interface{}) (success boo
258259
259260func (matcher * haveEventsSequenceMatcher ) FailureMessage (actual interface {}) (message string ) {
260261 // The type was already validated in Match, we can safely ignore the error
261- events , _ := actual .([]Event )
262+ events , _ := actual .([]* Event )
262263
263264 var output strings.Builder
264265
@@ -277,7 +278,7 @@ func (matcher *haveEventsSequenceMatcher) FailureMessage(actual interface{}) (me
277278
278279func (matcher * haveEventsSequenceMatcher ) NegatedFailureMessage (actual interface {}) (message string ) {
279280 // The type was already validated in Match, we can safely ignore the error
280- events , _ := actual .([]Event )
281+ events , _ := actual .([]* Event )
281282
282283 var output strings.Builder
283284 output .WriteString ("Expecte events\n " )
0 commit comments