Skip to content

Commit

Permalink
Fix merge problems
Browse files Browse the repository at this point in the history
  • Loading branch information
gfariasalves-ionos committed Jan 18, 2024
1 parent 8e5ffca commit 97dd000
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
10 changes: 5 additions & 5 deletions internal/service/cloud/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ func (s *Service) createLAN() error {
return fmt.Errorf("unable to create LAN in data center %s: %w", s.dataCenterID(), err)
}

if len(s.scope.ClusterScope.IonosCluster.Status.CurrentRequestByDataCenter) == 0 {
s.scope.ClusterScope.IonosCluster.Status.CurrentRequestByDataCenter = make(map[string]infrav1.ProvisioningRequest)
if len(s.scope.ClusterScope.IonosCluster.Status.CurrentRequestByDatacenter) == 0 {
s.scope.ClusterScope.IonosCluster.Status.CurrentRequestByDatacenter = make(map[string]infrav1.ProvisioningRequest)
}
s.scope.ClusterScope.IonosCluster.Status.CurrentRequestByDatacenter[s.dataCenterID()] = infrav1.ProvisioningRequest{
Method: http.MethodPost,
Expand All @@ -209,10 +209,10 @@ func (s *Service) deleteLAN(lanID string) error {
return fmt.Errorf("unable to request LAN deletion in data center: %w", err)
}

if s.scope.ClusterScope.IonosCluster.Status.CurrentRequest == nil {
s.scope.ClusterScope.IonosCluster.Status.CurrentRequest = make(map[string]infrav1.ProvisioningRequest)
if s.scope.ClusterScope.IonosCluster.Status.CurrentRequestByDatacenter == nil {
s.scope.ClusterScope.IonosCluster.Status.CurrentRequestByDatacenter = make(map[string]infrav1.ProvisioningRequest)
}
s.scope.ClusterScope.IonosCluster.Status.CurrentRequestByDataCenter[s.dataCenterID()] = infrav1.ProvisioningRequest{
s.scope.ClusterScope.IonosCluster.Status.CurrentRequestByDatacenter[s.dataCenterID()] = infrav1.ProvisioningRequest{
Method: http.MethodDelete,
RequestPath: requestPath,
State: infrav1.RequestStatusQueued,
Expand Down
54 changes: 27 additions & 27 deletions internal/service/cloud/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func (s *ServiceTestSuite) TestNetworkLANName() {
func (s *ServiceTestSuite) Test_Network_CreateLAN_Successful() {
s.createLANCall().Return(reqPath, nil).Once()
s.NoError(s.service.createLAN())
s.Contains(s.infraCluster.Status.CurrentRequest, s.service.dataCenterID(), "request should be stored in status")
req := s.infraCluster.Status.CurrentRequest[s.service.dataCenterID()]
s.Contains(s.infraCluster.Status.CurrentRequestByDatacenter, s.service.dataCenterID(), "request should be stored in status")
req := s.infraCluster.Status.CurrentRequestByDatacenter[s.service.dataCenterID()]
s.Equal(reqPath, req.RequestPath, "request path should be stored in status")
s.Equal(http.MethodPost, req.Method, "request method should be stored in status")
s.Equal(infrav1.RequestStatusQueued, req.State, "request status should be stored in status")
Expand All @@ -31,15 +31,15 @@ func (s *ServiceTestSuite) Test_Network_CreateLAN_Error_API() {
s.createLANCall().Return("", errMock).Once()
err := s.service.createLAN()
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.NotContains(s.infraCluster.Status.CurrentRequest, s.service.dataCenterID(), "request should not be stored in status")
s.ErrorIs(err, errMock)
s.NotContains(s.infraCluster.Status.CurrentRequestByDatacenter, s.service.dataCenterID(), "request should not be stored in status")
}

func (s *ServiceTestSuite) Test_Network_DeleteLAN_Successful() {
s.deleteLANCall(lanID).Return(reqPath, nil).Once()
s.NoError(s.service.deleteLAN(lanID))
s.Contains(s.infraCluster.Status.CurrentRequest, s.service.dataCenterID(), "request should be stored in status")
req := s.infraCluster.Status.CurrentRequest[s.service.dataCenterID()]
s.Contains(s.infraCluster.Status.CurrentRequestByDatacenter, s.service.dataCenterID(), "request should be stored in status")
req := s.infraCluster.Status.CurrentRequestByDatacenter[s.service.dataCenterID()]
s.Equal(reqPath, req.RequestPath, "request path should be stored in status")
s.Equal(http.MethodDelete, req.Method, "request method should be stored in status")
s.Equal(infrav1.RequestStatusQueued, req.State, "request status should be stored in status")
Expand All @@ -49,8 +49,8 @@ func (s *ServiceTestSuite) Test_Network_DeleteLAN_Error_API() {
s.deleteLANCall(lanID).Return("", errMock).Once()
err := s.service.deleteLAN(lanID)
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.NotContains(s.infraCluster.Status.CurrentRequest, s.service.dataCenterID(), "request should not be stored in status")
s.ErrorIs(err, errMock)
s.NotContains(s.infraCluster.Status.CurrentRequestByDatacenter, s.service.dataCenterID(), "request should not be stored in status")
}

func (s *ServiceTestSuite) Test_Network_GetLAN_Successful() {
Expand All @@ -66,7 +66,7 @@ func (s *ServiceTestSuite) Test_Network_GetLAN_Error_API() {
s.listLANsCall().Return(nil, errMock).Once()
lan, err := s.service.GetLAN()
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.ErrorIs(err, errMock)
s.Nil(lan)
}

Expand Down Expand Up @@ -197,20 +197,20 @@ func (s *ServiceTestSuite) Test_Network_CheckForPendingLANRequest_Error_API() {
s.getRequestsCall().Return(nil, errMock).Once()
request, err := s.service.checkForPendingLANRequest(http.MethodDelete, lanID)
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.ErrorIs(err, errMock)
s.Empty(request)
}

func (s *ServiceTestSuite) Test_Network_RemoveLANPendingRequestFromCluster_Successful() {
s.infraCluster.Status.CurrentRequest = map[string]infrav1.ProvisioningRequest{
s.infraCluster.Status.CurrentRequestByDatacenter = map[string]infrav1.ProvisioningRequest{
s.service.dataCenterID(): {
RequestPath: reqPath,
Method: http.MethodDelete,
State: sdk.RequestStatusQueued,
},
}
s.NoError(s.service.removeLANPendingRequestFromCluster())
s.NotContains(s.infraCluster.Status.CurrentRequest, s.service.dataCenterID(), "request should be removed from status")
s.NotContains(s.infraCluster.Status.CurrentRequestByDatacenter, s.service.dataCenterID(), "request should be removed from status")
}

func (s *ServiceTestSuite) Test_Network_RemoveLANPendingRequestFromCluster_NoRequest() {
Expand All @@ -224,8 +224,8 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLAN_NoExistingLAN_NoRequest_Cre
requeue, err := s.service.ReconcileLAN()
s.NoError(err)
s.True(requeue)
s.Contains(s.infraCluster.Status.CurrentRequest, s.service.dataCenterID())
req := s.infraCluster.Status.CurrentRequest[s.service.dataCenterID()]
s.Contains(s.infraCluster.Status.CurrentRequestByDatacenter, s.service.dataCenterID())
req := s.infraCluster.Status.CurrentRequestByDatacenter[s.service.dataCenterID()]
s.Equal(reqPath, req.RequestPath, "Request path is different than expected")
s.Equal(http.MethodPost, req.Method, "Request method is different than expected")
s.Equal(infrav1.RequestStatusQueued, req.State, "Request state is different than expected")
Expand Down Expand Up @@ -286,7 +286,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLAN_Error_API_ListingLANs() {
s.listLANsCall().Return(nil, errMock).Once()
requeue, err := s.service.ReconcileLAN()
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.ErrorIs(err, errMock)
s.False(requeue)
}

Expand All @@ -295,7 +295,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLAN_Error_API_GetRequests() {
s.getRequestsCall().Return(nil, errMock).Once()
requeue, err := s.service.ReconcileLAN()
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.ErrorIs(err, errMock)
s.False(requeue)
}

Expand All @@ -305,7 +305,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLAN_Error_API_CreateLAN() {
s.createLANCall().Return("", errMock).Once()
requeue, err := s.service.ReconcileLAN()
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.ErrorIs(err, errMock)
s.False(requeue)
}

Expand All @@ -315,7 +315,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLAN_Error_API_ListingLAN_Reques
s.listLANsCall().Return(&sdk.Lans{Items: &[]sdk.Lan{}}, errMock).Once()
requeue, err := s.service.ReconcileLAN()
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.ErrorIs(err, errMock)
s.False(requeue)
}

Expand All @@ -326,8 +326,8 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLANDelete_LANExists_NoPendingRe
requeue, err := s.service.ReconcileLANDeletion()
s.NoError(err)
s.True(requeue)
s.Contains(s.infraCluster.Status.CurrentRequest, s.service.dataCenterID())
req := s.infraCluster.Status.CurrentRequest[s.service.dataCenterID()]
s.Contains(s.infraCluster.Status.CurrentRequestByDatacenter, s.service.dataCenterID())
req := s.infraCluster.Status.CurrentRequestByDatacenter[s.service.dataCenterID()]
s.Equal(reqPath, req.RequestPath, "Request path is different than expected")
s.Equal(http.MethodDelete, req.Method, "Request method is different than expected")
s.Equal(infrav1.RequestStatusQueued, req.State, "Request state is different than expected")
Expand All @@ -341,7 +341,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLANDelete_LANExists_NoPendingRe
requeue, err := s.service.ReconcileLANDeletion()
s.NoError(err)
s.False(requeue)
s.NotContains(s.infraCluster.Status.CurrentRequest, s.service.dataCenterID())
s.NotContains(s.infraCluster.Status.CurrentRequestByDatacenter, s.service.dataCenterID())
}

func (s *ServiceTestSuite) Test_Network_ReconcileLANDelete_LANExists_ExistingRequest_InProgress() {
Expand Down Expand Up @@ -404,7 +404,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLANDelete_LANExists_ExistingReq
requeue, err := s.service.ReconcileLANDeletion()
s.NoError(err)
s.False(requeue)
s.NotContains(s.infraCluster.Status.CurrentRequest, s.service.dataCenterID())
s.NotContains(s.infraCluster.Status.CurrentRequestByDatacenter, s.service.dataCenterID())
}

func (s *ServiceTestSuite) Test_Network_ReconcileLANDelete_LANDoesNotExist() {
Expand All @@ -418,7 +418,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLANDelete_Error_API_ListingLANs
s.listLANsCall().Return(nil, errMock).Once()
requeue, err := s.service.ReconcileLANDeletion()
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.ErrorIs(err, errMock)
s.False(requeue)
}

Expand All @@ -427,7 +427,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLANDelete_Error_API_GetRequests
s.getRequestsCall().Return(nil, errMock).Once()
requeue, err := s.service.ReconcileLANDeletion()
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.ErrorIs(err, errMock)
s.False(requeue)
}

Expand All @@ -437,7 +437,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLANDelete_Error_API_DeleteLAN()
s.deleteLANCall(lanID).Return("", errMock).Once()
requeue, err := s.service.ReconcileLANDeletion()
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.ErrorIs(err, errMock)
s.False(requeue)
}

Expand All @@ -447,7 +447,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLANDelete_Error_API_ListingLAN_
s.listLANsCall().Return(&sdk.Lans{Items: &[]sdk.Lan{}}, errMock).Once()
requeue, err := s.service.ReconcileLANDeletion()
s.Error(err)
s.ErrorIs(err, errMock, "different error returned")
s.ErrorIs(err, errMock)
s.False(requeue)
}

Expand All @@ -456,7 +456,7 @@ func (s *ServiceTestSuite) Test_Network_ReconcileLANDelete_NoLANExists() {
requeue, err := s.service.ReconcileLANDeletion()
s.NoError(err)
s.False(requeue)
s.NotContains(s.infraCluster.Status.CurrentRequest, s.service.dataCenterID())
s.NotContains(s.infraCluster.Status.CurrentRequestByDatacenter, s.service.dataCenterID())
}

const (
Expand Down
6 changes: 1 addition & 5 deletions internal/service/cloud/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,13 @@ func (s *ServiceTestSuite) SetupTest() {
AvailabilityZone: infrav1.AvailabilityZoneAuto,
MemoryMB: 4096,
CPUFamily: "AMD_OPTERON",
Disk: infrav1.Volume{
Disk: &infrav1.Volume{
Name: "test-machine-hdd",
DiskType: infrav1.VolumeDiskTypeHDD,
SizeGB: 20,
AvailabilityZone: infrav1.AvailabilityZoneAuto,
SSHKeys: []string{"ssh-rsa AAAAB3Nz"},
},
Network: &infrav1.Network{
IPs: []string{"1.2.3.4"},
UseDHCP: ptr.To(true),
},
},
Status: infrav1.IonosCloudMachineStatus{},
}
Expand Down

0 comments on commit 97dd000

Please sign in to comment.