From d6acad09685b4c52c326dcfc58452c8b814896ac Mon Sep 17 00:00:00 2001 From: Radu Mocanu Date: Mon, 20 May 2024 12:13:02 +0300 Subject: [PATCH] fixed tests --- internal/utils/mocks/ClientService.go | 15 +++++++++++++++ ionoscloud_test.go | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/internal/utils/mocks/ClientService.go b/internal/utils/mocks/ClientService.go index 54e5c0f..ebf82bf 100644 --- a/internal/utils/mocks/ClientService.go +++ b/internal/utils/mocks/ClientService.go @@ -304,6 +304,21 @@ func (mr *MockClientServiceMockRecorder) GetTemplates() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTemplates", reflect.TypeOf((*MockClientService)(nil).GetTemplates)) } +// PatchNat mocks base method. +func (m *MockClientService) PatchNat(datacenterId, natId, name string, publicIps []string, lansToGateways []ionoscloud.NatGatewayLanProperties) (*ionoscloud.NatGateway, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PatchNat", datacenterId, natId, name, publicIps, lansToGateways) + ret0, _ := ret[0].(*ionoscloud.NatGateway) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PatchNat indicates an expected call of PatchNat. +func (mr *MockClientServiceMockRecorder) PatchNat(datacenterId, natId, name, publicIps, lansToGateways interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PatchNat", reflect.TypeOf((*MockClientService)(nil).PatchNat), datacenterId, natId, name, publicIps, lansToGateways) +} + // RemoveDatacenter mocks base method. func (m *MockClientService) RemoveDatacenter(datacenterId string) error { m.ctrl.T.Helper() diff --git a/ionoscloud_test.go b/ionoscloud_test.go index d5469a4..ab9712f 100644 --- a/ionoscloud_test.go +++ b/ionoscloud_test.go @@ -205,6 +205,9 @@ var ( Name: &testVar, }, } + nats = &sdkgo.NatGateways{ + Items: &[]sdkgo.NatGateway{*nat}, + } dcs = &sdkgo.Datacenters{ Items: &[]sdkgo.Datacenter{*dc}, } @@ -362,9 +365,10 @@ func TestPreCreateCheckDataCenterIdErr(t *testing.T) { driver.DatacenterId = datacenterId clientMock.EXPECT().GetDatacenter(driver.DatacenterId).Return(dc, nil) clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil) - clientMock.EXPECT().GetImageById(defaultImageAlias).Return(&sdkgo.Image{}, fmt.Errorf("no image found with this id")) + clientMock.EXPECT().GetImageById(defaultImageAlias).Return(nil, fmt.Errorf("no image found with this id")) clientMock.EXPECT().GetImages().Return(&images, nil) clientMock.EXPECT().GetLans(driver.DatacenterId).Return(&lans, nil) + clientMock.EXPECT().GetNats(driver.DatacenterId).Return(nats, nil) err := driver.PreCreateCheck() assert.NoError(t, err) } @@ -410,6 +414,7 @@ func TestPreCreateLans(t *testing.T) { clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil) clientMock.EXPECT().GetImageById(defaultImageAlias).Return(&sdkgo.Image{}, fmt.Errorf("no image found with this id")) clientMock.EXPECT().GetImages().Return(&images, nil) + clientMock.EXPECT().GetNats(driver.DatacenterId).Return(nats, nil) err := driver.PreCreateCheck() assert.True(t, reflect.DeepEqual(driver.AdditionalLansIds, []int{lanId1Int})) assert.NoError(t, err) @@ -505,6 +510,7 @@ func TestCreateLanProvided(t *testing.T) { clientMock.EXPECT().GetDatacenter(*dc.Id).Return(dc, nil), clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil), clientMock.EXPECT().GetImageById(imageAlias).Return(&sdkgo.Image{Id: sdkgo.ToPtr(testImageIdVar)}, nil), + clientMock.EXPECT().GetNats(*dc.Id).Return(nats, nil), clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil), clientMock.EXPECT().GetImageById(imageAlias).Return(&sdkgo.Image{Id: sdkgo.ToPtr(testImageIdVar)}, nil), @@ -587,6 +593,7 @@ func TestCreatePropertiesSet(t *testing.T) { clientMock.EXPECT().GetDatacenter(*dc.Id).Return(dc, nil), clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil), clientMock.EXPECT().GetImageById(imageAlias).Return(&sdkgo.Image{Id: sdkgo.ToPtr(testImageIdVar)}, nil), + clientMock.EXPECT().GetNats(*dc.Id).Return(nats, nil), clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil), clientMock.EXPECT().GetImageById(imageAlias).Return(&sdkgo.Image{Id: sdkgo.ToPtr(testImageIdVar)}, nil), @@ -674,6 +681,7 @@ func TestCreateCubePropertiesSet(t *testing.T) { clientMock.EXPECT().GetDatacenter(*dc.Id).Return(dc, nil), clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil), clientMock.EXPECT().GetImageById(imageAlias).Return(&sdkgo.Image{Id: sdkgo.ToPtr(testImageIdVar)}, nil), + clientMock.EXPECT().GetNats(*dc.Id).Return(nats, nil), clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil), clientMock.EXPECT().GetImageById(imageAlias).Return(&sdkgo.Image{Id: sdkgo.ToPtr(testImageIdVar)}, nil), @@ -746,6 +754,7 @@ func TestCreateNatPublicIps(t *testing.T) { clientMock.EXPECT().GetDatacenter(*dc.Id).Return(dc, nil), clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil), clientMock.EXPECT().GetImageById(imageAlias).Return(&sdkgo.Image{Id: sdkgo.ToPtr(testImageIdVar)}, nil), + clientMock.EXPECT().GetNats(*dc.Id).Return(nats, nil), clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil), clientMock.EXPECT().GetImageById(imageAlias).Return(&sdkgo.Image{Id: sdkgo.ToPtr(testImageIdVar)}, nil), @@ -821,6 +830,7 @@ func TestCreateNat(t *testing.T) { clientMock.EXPECT().GetDatacenter(*dc.Id).Return(dc, nil), clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil), clientMock.EXPECT().GetImageById(imageAlias).Return(&sdkgo.Image{Id: sdkgo.ToPtr(testImageIdVar)}, nil), + clientMock.EXPECT().GetNats(*dc.Id).Return(nats, nil), clientMock.EXPECT().GetLocationById("us", "ewr").Return(location, nil), clientMock.EXPECT().GetImageById(imageAlias).Return(&sdkgo.Image{Id: sdkgo.ToPtr(testImageIdVar)}, nil),