File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,11 @@ func (a *AllActionsTracker[T]) ListActions() []Action {
92
92
93
93
func (a * AllActionsTracker [T ]) RequestsForAction (action Action ) []SerializedRequestish {
94
94
ret := []SerializedRequestish {}
95
- mutations := a .actionToTracker [action ].Mutations ()
95
+ tracker , ok := a .actionToTracker [action ]
96
+ if ! ok {
97
+ return nil
98
+ }
99
+ mutations := tracker .Mutations ()
96
100
for _ , mutation := range mutations {
97
101
ret = append (ret , mutation )
98
102
}
@@ -101,7 +105,11 @@ func (a *AllActionsTracker[T]) RequestsForAction(action Action) []SerializedRequ
101
105
102
106
func (a * AllActionsTracker [T ]) RequestsForResource (metadata ActionMetadata ) []SerializedRequestish {
103
107
ret := []SerializedRequestish {}
104
- mutations := a .actionToTracker [metadata .Action ].Mutations ()
108
+ tracker , ok := a .actionToTracker [metadata .Action ]
109
+ if ! ok {
110
+ return nil
111
+ }
112
+ mutations := tracker .Mutations ()
105
113
for _ , mutation := range mutations {
106
114
if mutation .GetSerializedRequest ().GetLookupMetadata () == metadata {
107
115
ret = append (ret , mutation )
Original file line number Diff line number Diff line change
1
+ package manifestclient_test
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/openshift/library-go/pkg/manifestclient"
7
+ )
8
+
9
+ // TestNoPanicFromAllActionTracker
10
+ // is a simple test to ensure that the read methods
11
+ // of NewAllActionsTracker do not panic on an empty instance.
12
+ func TestNoPanicFromAllActionTracker (t * testing.T ) {
13
+ target := manifestclient .NewAllActionsTracker [manifestclient.FileOriginatedSerializedRequest ]()
14
+
15
+ if actions := target .ListActions (); len (actions ) != 0 {
16
+ t .Errorf ("ListActions() returned non empty response: %v" , actions )
17
+ }
18
+
19
+ if reqs := target .AllRequests (); len (reqs ) != 0 {
20
+ t .Errorf ("AllRequests() returned non empty response: %v" , reqs )
21
+ }
22
+
23
+ ret := target .RequestsForAction (manifestclient .ActionUpdate )
24
+ if ret != nil {
25
+ t .Errorf ("RequestsForAction() returned non nil response: %v" , ret )
26
+ }
27
+
28
+ ret = target .RequestsForResource (manifestclient.ActionMetadata {Action : manifestclient .ActionApply })
29
+ if ret != nil {
30
+ t .Errorf ("RequestsForResource() returned non nil response: %v" , ret )
31
+ }
32
+
33
+ // just make sure it doens panic
34
+ _ = target .DeepCopy ()
35
+ }
You can’t perform that action at this time.
0 commit comments