@@ -176,7 +176,6 @@ func TestClient_CreateServer(t *testing.T) {
176
176
securityGroupID * string
177
177
rootVolumeSize scw.Size
178
178
rootVolumeType instance.VolumeVolumeType
179
- publicIPs []string
180
179
tags []string
181
180
}
182
181
tests := []struct {
@@ -203,7 +202,6 @@ func TestClient_CreateServer(t *testing.T) {
203
202
securityGroupID : scw .StringPtr (securityGroupID ),
204
203
rootVolumeSize : rootVolumeSize ,
205
204
rootVolumeType : instance .VolumeVolumeTypeBSSD ,
206
- publicIPs : []string {"42.42.42.42" },
207
205
tags : []string {"tag1" , "tag2" , "tag3" },
208
206
},
209
207
expect : func (d * mock_client.MockInstanceAPIMockRecorder ) {
@@ -227,8 +225,7 @@ func TestClient_CreateServer(t *testing.T) {
227
225
Boot : scw .BoolPtr (true ),
228
226
},
229
227
},
230
- Tags : []string {"tag1" , "tag2" , "tag3" , createdByTag },
231
- PublicIPs : & []string {"42.42.42.42" },
228
+ Tags : []string {"tag1" , "tag2" , "tag3" , createdByTag },
232
229
}, gomock .Any ()).Return (& instance.CreateServerResponse {
233
230
Server : & instance.Server {
234
231
Name : "server" ,
@@ -316,7 +313,7 @@ func TestClient_CreateServer(t *testing.T) {
316
313
region : tt .fields .region ,
317
314
instance : instanceMock ,
318
315
}
319
- got , err := c .CreateServer (tt .args .ctx , tt .args .zone , tt .args .name , tt .args .commercialType , tt .args .imageID , tt .args .placementGroupID , tt .args .securityGroupID , tt .args .rootVolumeSize , tt .args .rootVolumeType , tt .args .publicIPs , tt . args . tags )
316
+ got , err := c .CreateServer (tt .args .ctx , tt .args .zone , tt .args .name , tt .args .commercialType , tt .args .imageID , tt .args .placementGroupID , tt .args .securityGroupID , tt .args .rootVolumeSize , tt .args .rootVolumeType , tt .args .tags )
320
317
if (err != nil ) != tt .wantErr {
321
318
t .Errorf ("Client.CreateServer() error = %v, wantErr %v" , err , tt .wantErr )
322
319
return
@@ -1731,3 +1728,82 @@ func TestClient_FindSecurityGroup(t *testing.T) {
1731
1728
})
1732
1729
}
1733
1730
}
1731
+
1732
+ func TestClient_UpdateServerPublicIPs (t * testing.T ) {
1733
+ t .Parallel ()
1734
+ type fields struct {
1735
+ projectID string
1736
+ region scw.Region
1737
+ }
1738
+ type args struct {
1739
+ ctx context.Context
1740
+ zone scw.Zone
1741
+ id string
1742
+ publicIPIDs []string
1743
+ }
1744
+ tests := []struct {
1745
+ name string
1746
+ fields fields
1747
+ args args
1748
+ want * instance.Server
1749
+ wantErr bool
1750
+ expect func (d * mock_client.MockInstanceAPIMockRecorder )
1751
+ }{
1752
+ {
1753
+ name : "update public IPs" ,
1754
+ fields : fields {
1755
+ projectID : projectID ,
1756
+ region : scw .RegionFrPar ,
1757
+ },
1758
+ args : args {
1759
+ ctx : context .TODO (),
1760
+ zone : scw .ZoneFrPar1 ,
1761
+ id : serverID ,
1762
+ publicIPIDs : []string {ipID },
1763
+ },
1764
+ want : & instance.Server {
1765
+ ID : serverID ,
1766
+ },
1767
+ expect : func (d * mock_client.MockInstanceAPIMockRecorder ) {
1768
+ d .UpdateServer (& instance.UpdateServerRequest {
1769
+ Zone : scw .ZoneFrPar1 ,
1770
+ ServerID : serverID ,
1771
+ PublicIPs : & []string {ipID },
1772
+ }, gomock .Any ()).Return (& instance.UpdateServerResponse {
1773
+ Server : & instance.Server {
1774
+ ID : serverID ,
1775
+ },
1776
+ }, nil )
1777
+ },
1778
+ },
1779
+ }
1780
+ for _ , tt := range tests {
1781
+ t .Run (tt .name , func (t * testing.T ) {
1782
+ t .Parallel ()
1783
+
1784
+ mockCtrl := gomock .NewController (t )
1785
+ defer mockCtrl .Finish ()
1786
+
1787
+ instanceMock := mock_client .NewMockInstanceAPI (mockCtrl )
1788
+
1789
+ // Every API call must be preceded by a zone check.
1790
+ instanceMock .EXPECT ().Zones ().Return (tt .fields .region .GetZones ())
1791
+
1792
+ tt .expect (instanceMock .EXPECT ())
1793
+
1794
+ c := & Client {
1795
+ projectID : tt .fields .projectID ,
1796
+ region : tt .fields .region ,
1797
+ instance : instanceMock ,
1798
+ }
1799
+ got , err := c .UpdateServerPublicIPs (tt .args .ctx , tt .args .zone , tt .args .id , tt .args .publicIPIDs )
1800
+ if (err != nil ) != tt .wantErr {
1801
+ t .Errorf ("Client.UpdateServerPublicIPs() error = %v, wantErr %v" , err , tt .wantErr )
1802
+ return
1803
+ }
1804
+ if ! reflect .DeepEqual (got , tt .want ) {
1805
+ t .Errorf ("Client.UpdateServerPublicIPs() = %v, want %v" , got , tt .want )
1806
+ }
1807
+ })
1808
+ }
1809
+ }
0 commit comments