Skip to content

Commit f33b415

Browse files
Merge pull request #5453 from sergiordlr/mco_1999_pointers_and_permissions_in_lists
MCO-1999: align extended tests code with private repo. Pointers and pe…
2 parents 5051cce + 8b17be5 commit f33b415

17 files changed

+104
-103
lines changed

test/extended-priv/configmap.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,24 @@ func (cm *ConfigMap) GetDataValueOrFail(key string) string {
7171
return value
7272
}
7373

74-
// GetAll returns a []ConfigMap list with all existing pinnedimageset sorted by creation timestamp
75-
func (cml *ConfigMapList) GetAll() ([]ConfigMap, error) {
74+
// GetAll returns a []*ConfigMap list with all existing pinnedimageset sorted by creation timestamp
75+
func (cml *ConfigMapList) GetAll() ([]*ConfigMap, error) {
7676
cml.ResourceList.SortByTimestamp()
7777
allResources, err := cml.ResourceList.GetAll()
7878
if err != nil {
7979
return nil, err
8080
}
81-
all := make([]ConfigMap, 0, len(allResources))
81+
all := make([]*ConfigMap, 0, len(allResources))
8282

8383
for _, res := range allResources {
84-
all = append(all, *NewConfigMap(cml.oc, res.namespace, res.name))
84+
all = append(all, NewConfigMap(cml.oc, res.namespace, res.name))
8585
}
8686

8787
return all, nil
8888
}
8989

90-
// GetAllOrFail returns a []ConfigMap list with all existing pinnedimageset sorted by creation time, if any error happens it fails the test
91-
func (cml *ConfigMapList) GetAllOrFail() []ConfigMap {
90+
// GetAllOrFail returns a []*ConfigMap list with all existing pinnedimageset sorted by creation time, if any error happens it fails the test
91+
func (cml *ConfigMapList) GetAllOrFail() []*ConfigMap {
9292
all, err := cml.GetAll()
9393
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the list of existing ConfigMap in the cluster")
9494
return all

test/extended-priv/controlplanemachineset.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func (cpms ControlPlaneMachineSet) SetUserDataSecret(userDataSecretName string)
263263
}
264264

265265
// GetMachines returns a slice with the machines created for this ControlPlaneMachineSet
266-
func (cpms ControlPlaneMachineSet) GetMachines() ([]Machine, error) {
266+
func (cpms ControlPlaneMachineSet) GetMachines() ([]*Machine, error) {
267267
ml := NewMachineList(cpms.oc, cpms.GetNamespace())
268268
ml.ByLabel("machine.openshift.io/cluster-api-machine-role=master")
269269
ml.ByLabel("machine.openshift.io/cluster-api-machine-type=master")
@@ -272,7 +272,7 @@ func (cpms ControlPlaneMachineSet) GetMachines() ([]Machine, error) {
272272
}
273273

274274
// GetMachinesOrFail get machines from ControlPlaneMachineSet or fail the test if any error occurred
275-
func (cpms ControlPlaneMachineSet) GetMachinesOrFail() []Machine {
275+
func (cpms ControlPlaneMachineSet) GetMachinesOrFail() []*Machine {
276276
ml, err := cpms.GetMachines()
277277
o.Expect(err).NotTo(o.HaveOccurred(), "Get machines of ControlPlaneMachineSet %s failed", cpms.GetName())
278278
return ml
@@ -304,23 +304,23 @@ func (cpms ControlPlaneMachineSet) GetNodesOrFail() []*Node {
304304
return nodes
305305
}
306306

307-
// GetAll returns a []ControlPlaneMachineSet list with all existing ControlPlaneMachineSets
308-
func (cpmsl *ControlPlaneMachineSetList) GetAll() ([]ControlPlaneMachineSet, error) {
307+
// GetAll returns a []*ControlPlaneMachineSet list with all existing ControlPlaneMachineSets
308+
func (cpmsl *ControlPlaneMachineSetList) GetAll() ([]*ControlPlaneMachineSet, error) {
309309
allCPMSResources, err := cpmsl.ResourceList.GetAll()
310310
if err != nil {
311311
return nil, err
312312
}
313-
allCPMS := make([]ControlPlaneMachineSet, 0, len(allCPMSResources))
313+
allCPMS := make([]*ControlPlaneMachineSet, 0, len(allCPMSResources))
314314

315315
for _, cpmsRes := range allCPMSResources {
316-
allCPMS = append(allCPMS, *NewControlPlaneMachineSet(cpmsl.oc, cpmsRes.GetNamespace(), cpmsRes.GetName()))
316+
allCPMS = append(allCPMS, NewControlPlaneMachineSet(cpmsl.oc, cpmsRes.GetNamespace(), cpmsRes.GetName()))
317317
}
318318

319319
return allCPMS, nil
320320
}
321321

322-
// GetAllOrFail returns a []ControlPlaneMachineSet list with all existing ControlPlaneMachineSets and fail the test if it is not possible
323-
func (cpmsl *ControlPlaneMachineSetList) GetAllOrFail() []ControlPlaneMachineSet {
322+
// GetAllOrFail returns a []*ControlPlaneMachineSet list with all existing ControlPlaneMachineSets and fail the test if it is not possible
323+
func (cpmsl *ControlPlaneMachineSetList) GetAllOrFail() []*ControlPlaneMachineSet {
324324
allCpms, err := cpmsl.GetAll()
325325
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the list of existing ControlPlaneMachineSets")
326326

test/extended-priv/events.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
202202
func (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,14 +259,14 @@ func (matcher *haveEventsSequenceMatcher) Match(actual interface{}) (success boo
258259

259260
func (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

265266
if len(events) == 0 {
266267
output.WriteString("No events in the list\n")
267268
} else {
268-
output.WriteString("Expecte events\n")
269+
output.WriteString("Expect events\n")
269270
for _, event := range events {
270271
output.WriteString(fmt.Sprintf("- %s\n", event))
271272
}
@@ -277,10 +278,10 @@ func (matcher *haveEventsSequenceMatcher) FailureMessage(actual interface{}) (me
277278

278279
func (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
283-
output.WriteString("Expecte events\n")
284+
output.WriteString("Expect events\n")
284285
for _, event := range events {
285286
output.WriteString(fmt.Sprintf("- %s\n", event))
286287
}

test/extended-priv/generic_behaviour_validation.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
type Checker interface {
14-
Check(checkedNodes ...Node)
14+
Check(checkedNodes ...*Node)
1515
}
1616

1717
type CommandOutputChecker struct {
@@ -21,7 +21,7 @@ type CommandOutputChecker struct {
2121
Desc string
2222
}
2323

24-
func (cOutChecker CommandOutputChecker) Check(checkedNodes ...Node) {
24+
func (cOutChecker CommandOutputChecker) Check(checkedNodes ...*Node) {
2525
msg := "Executing verification commands"
2626
if cOutChecker.Desc != "" {
2727
msg = cOutChecker.Desc
@@ -47,7 +47,7 @@ type RemoteFileChecker struct {
4747
Desc string
4848
}
4949

50-
func (rfc RemoteFileChecker) Check(checkedNodes ...Node) {
50+
func (rfc RemoteFileChecker) Check(checkedNodes ...*Node) {
5151
msg := fmt.Sprintf("Checking file: %s", rfc.FileFullPath)
5252
if rfc.Desc != "" {
5353
msg = rfc.Desc
@@ -65,12 +65,12 @@ func (rfc RemoteFileChecker) Check(checkedNodes ...Node) {
6565
}
6666

6767
// checkDrainAction checks that the drain action in the node is the expected one (drainSkipped)
68-
func checkDrainAction(drainSkipped bool, node Node, controller *Controller) {
68+
func checkDrainAction(drainSkipped bool, node *Node, controller *Controller) {
6969
checkDrainActionWithGomega(drainSkipped, node, controller, o.Default)
7070
}
7171

7272
// checkDrainActionWithGomega checks that the drain action in the node is the expected one (drainSkipped). It accepts an extra Gomega parameter that allows the function to be used in the Eventually gomega matchers
73-
func checkDrainActionWithGomega(drainExecuted bool, node Node, controller *Controller, gm o.Gomega) {
73+
func checkDrainActionWithGomega(drainExecuted bool, node *Node, controller *Controller, gm o.Gomega) {
7474
var (
7575
execDrainLogMsg = "initiating drain"
7676
)
@@ -97,12 +97,12 @@ func checkDrainActionWithGomega(drainExecuted bool, node Node, controller *Contr
9797
}
9898

9999
// checkRebootAction checks that the reboot action in the node is the expected one (rebootSkipped)
100-
func checkRebootAction(rebootExecuted bool, node Node, startTime time.Time) {
100+
func checkRebootAction(rebootExecuted bool, node *Node, startTime time.Time) {
101101
checkRebootActionWithGomega(rebootExecuted, node, startTime, o.Default)
102102
}
103103

104104
// checkRebootActionWithGomega checks that the reboot action in the node is the expected one (rebootSkipped). It accepts an extra Gomega parameter that allows the function to be used in the Eventually gomega matchers
105-
func checkRebootActionWithGomega(rebootExecuted bool, node Node, startTime time.Time, gm o.Gomega) {
105+
func checkRebootActionWithGomega(rebootExecuted bool, node *Node, startTime time.Time, gm o.Gomega) {
106106
if rebootExecuted {
107107
logger.Infof("Checking that node %s was rebooted", node.GetName())
108108
gm.Expect(node.GetUptime()).Should(o.BeTemporally(">", startTime),

test/extended-priv/machine.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (m Machine) GetNode() (*Node, error) {
4141
return nil, fmt.Errorf("No node linked to this Machine. Machine: %s", m.GetName())
4242
}
4343

44-
return &(nodes[0]), nil
44+
return nodes[0], nil
4545
}
4646

4747
// GetNodeOrFail, call GetNode, fail the test if any error occurred
@@ -75,16 +75,16 @@ func NewMachineList(oc *exutil.CLI, namespace string) *MachineList {
7575
return &MachineList{*NewNamespacedResourceList(oc, MachineFullName, namespace)}
7676
}
7777

78-
// GetAll returns a []Machine slice with all existing nodes
79-
func (ml MachineList) GetAll() ([]Machine, error) {
78+
// GetAll returns a []*Machine slice with all existing nodes
79+
func (ml MachineList) GetAll() ([]*Machine, error) {
8080
allMResources, err := ml.ResourceList.GetAll()
8181
if err != nil {
8282
return nil, err
8383
}
84-
allMs := make([]Machine, 0, len(allMResources))
84+
allMs := make([]*Machine, 0, len(allMResources))
8585

8686
for _, mRes := range allMResources {
87-
allMs = append(allMs, *NewMachine(ml.oc, mRes.GetNamespace(), mRes.GetName()))
87+
allMs = append(allMs, NewMachine(ml.oc, mRes.GetNamespace(), mRes.GetName()))
8888
}
8989

9090
return allMs, nil

0 commit comments

Comments
 (0)