@@ -27,6 +27,7 @@ import (
2727 "github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
2828 "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
2929 . "github.com/onsi/gomega"
30+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
3132 infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7"
3233 "sigs.k8s.io/cluster-api-provider-openstack/pkg/clients/mock"
@@ -546,36 +547,56 @@ func Test_GarbageCollectErrorInstancesPort(t *testing.T) {
546547 portName2 := GetPortName (instanceName , nil , 1 )
547548
548549 tests := []struct {
549- name string
550- expect func (m * mock.MockNetworkClientMockRecorder )
550+ // man is the name of the test.
551+ name string
552+ // expect allows definition of any expected calls to the mock.
553+ expect func (m * mock.MockNetworkClientMockRecorder )
554+ // portOpts defines the instance ports as defined in the OSM spec.
555+ portOpts []infrav1.PortOpts
556+ // wantErr defines whether the test is supposed to fail.
551557 wantErr bool
552558 }{
553559 {
554560 name : "garbage collects all ports for an instance" ,
555561 expect : func (m * mock.MockNetworkClientMockRecorder ) {
556- p := []ports.Port {
557- {
558- ID : "9278e096-5c63-4ffb-9289-2bacf948dc51" ,
559- Name : "bar-0" ,
560- },
562+ o1 := ports.ListOpts {
563+ Name : portName1 ,
564+ }
565+ p1 := []ports.Port {
561566 {
562567 ID : portID1 ,
563568 Name : portName1 ,
564569 },
570+ }
571+ m .ListPort (o1 ).Return (p1 , nil )
572+ m .DeletePort (portID1 )
573+ o2 := ports.ListOpts {
574+ Name : portName2 ,
575+ }
576+ p2 := []ports.Port {
565577 {
566578 ID : portID2 ,
567579 Name : portName2 ,
568580 },
569581 }
570- m . ListPort (ports. ListOpts {}). Return ( p , nil )
571- m .DeletePort ( portID1 )
582+
583+ m .ListPort ( o2 ). Return ( p2 , nil )
572584 m .DeletePort (portID2 )
573585 },
586+ portOpts : []infrav1.PortOpts {
587+ {},
588+ {},
589+ },
574590 wantErr : false ,
575591 },
576592 }
577593
578- eventObject := & infrav1.OpenStackMachine {}
594+ eventObject := & infrav1.OpenStackMachine {
595+ ObjectMeta : metav1.ObjectMeta {
596+ Name : instanceName ,
597+ },
598+ }
599+
579600 for _ , tt := range tests {
580601 t .Run (tt .name , func (t * testing.T ) {
581602 g := NewWithT (t )
@@ -587,6 +608,7 @@ func Test_GarbageCollectErrorInstancesPort(t *testing.T) {
587608 err := s .GarbageCollectErrorInstancesPort (
588609 eventObject ,
589610 instanceName ,
611+ tt .portOpts ,
590612 )
591613 if tt .wantErr {
592614 g .Expect (err ).To (HaveOccurred ())
0 commit comments