-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test coverage for Network related methods/functions (#670)
* network tests * modified_names * fix_format
- Loading branch information
Showing
14 changed files
with
503 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"address": "192.168.1.1", | ||
"linode_id": 12345, | ||
"reserved": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"address": "192.168.1.1", | ||
"linode_id": 12345, | ||
"reserved": false | ||
}, | ||
{ | ||
"address": "192.168.1.2", | ||
"linode_id": 67890, | ||
"reserved": true | ||
} | ||
], | ||
"pages": 1, | ||
"results": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"range": "2600:3c00::/64", | ||
"region": "us-east", | ||
"prefix": 64, | ||
"route_target": "2600:3c00::1", | ||
"is_bgp": false, | ||
"linodes": [54321] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"range": "2600:3c00::/64", | ||
"region": "us-east", | ||
"prefix": 64, | ||
"route_target": "2600:3c00::1", | ||
"is_bgp": true, | ||
"linodes": [12345, 67890] | ||
} | ||
], | ||
"pages": 1, | ||
"page": 1, | ||
"results": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"range": "2600:3c00::/64", | ||
"region": "us-east", | ||
"prefix": 64, | ||
"route_target": "2600:3c00::1", | ||
"is_bgp": false, | ||
"linodes": [12345] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"range": "2600:3c00::/64", | ||
"region": "us-east", | ||
"prefix": 64, | ||
"route_target": "2600:3c00::1", | ||
"is_bgp": false, | ||
"linodes": [54321] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"range": "2600:3c00::/64", | ||
"region": "us-east", | ||
"prefix": 64, | ||
"route_target": "2600:3c00::1", | ||
"is_bgp": true, | ||
"linodes": [12345, 67890] | ||
} | ||
], | ||
"pages": 1, | ||
"results": 1 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"address": "192.168.1.30", | ||
"region": "us-west", | ||
"linode_id": 13579, | ||
"label": "test-ip-3", | ||
"created": "2025-02-03T12:00:00", | ||
"status": "reserved" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"address": "192.168.1.10", | ||
"region": "us-east", | ||
"linode_id": 12345, | ||
"label": "test-ip-1", | ||
"created": "2025-02-03T12:00:00", | ||
"status": "reserved" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"address": "192.168.1.10", | ||
"region": "us-east", | ||
"linode_id": 12345, | ||
"label": "test-ip-1", | ||
"created": "2025-02-03T12:00:00", | ||
"status": "reserved" | ||
}, | ||
{ | ||
"address": "192.168.1.20", | ||
"region": "us-west", | ||
"linode_id": 67890, | ||
"label": "test-ip-2", | ||
"created": "2025-02-03T12:00:00", | ||
"status": "reserved" | ||
} | ||
], | ||
"pages": 1, | ||
"results": 2 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package unit | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/linode/linodego" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIPUpdateAddressV2(t *testing.T) { | ||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
ip := "192.168.1.1" | ||
|
||
// Mock API response | ||
base.MockPut("networking/ips/"+ip, linodego.InstanceIP{ | ||
Address: ip, | ||
Reserved: true, | ||
}) | ||
|
||
updatedIP, err := base.Client.UpdateIPAddressV2(context.Background(), ip, linodego.IPAddressUpdateOptionsV2{ | ||
Reserved: linodego.Pointer(true), | ||
}) | ||
assert.NoError(t, err, "Expected no error when updating IP address") | ||
assert.NotNil(t, updatedIP, "Expected non-nil updated IP address") | ||
assert.Equal(t, ip, updatedIP.Address, "Expected updated IP address to match") | ||
assert.True(t, updatedIP.Reserved, "Expected Reserved to be true") | ||
} | ||
|
||
func TestIPAllocateReserve(t *testing.T) { | ||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
// Mock API response | ||
base.MockPost("networking/ips", linodego.InstanceIP{ | ||
Address: "192.168.1.3", | ||
Region: "us-east", | ||
Public: true, | ||
}) | ||
|
||
ip, err := base.Client.AllocateReserveIP(context.Background(), linodego.AllocateReserveIPOptions{ | ||
Type: "ipv4", | ||
Public: true, | ||
Region: "us-east", | ||
LinodeID: 12345, | ||
}) | ||
assert.NoError(t, err, "Expected no error when allocating reserve IP") | ||
assert.NotNil(t, ip, "Expected non-nil allocated IP") | ||
assert.Equal(t, "192.168.1.3", ip.Address, "Expected allocated IP address to match") | ||
assert.Equal(t, "us-east", ip.Region, "Expected Region to match") | ||
assert.True(t, ip.Public, "Expected Public to be true") | ||
} | ||
|
||
func TestIPAssignInstances(t *testing.T) { | ||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
// Mock API response | ||
base.MockPost("networking/ips/assign", nil) | ||
|
||
err := base.Client.InstancesAssignIPs(context.Background(), linodego.LinodesAssignIPsOptions{ | ||
Region: "us-east", | ||
Assignments: []linodego.LinodeIPAssignment{ | ||
{Address: "192.168.1.10", LinodeID: 123}, | ||
}, | ||
}) | ||
assert.NoError(t, err, "Expected no error when assigning IPs to instances") | ||
} | ||
|
||
func TestIPShareAddresses(t *testing.T) { | ||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
// Mock API response | ||
base.MockPost("networking/ips/share", nil) | ||
|
||
err := base.Client.ShareIPAddresses(context.Background(), linodego.IPAddressesShareOptions{ | ||
IPs: []string{"192.168.1.20"}, | ||
LinodeID: 456, | ||
}) | ||
assert.NoError(t, err, "Expected no error when sharing IP addresses") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package unit | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/linode/linodego" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIPIPv6Pools_List(t *testing.T) { | ||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
mockResponse := struct { | ||
Data []linodego.IPv6Range `json:"data"` | ||
}{ | ||
Data: []linodego.IPv6Range{ | ||
{ | ||
Range: "2600:3c00::/64", | ||
Region: "us-east", | ||
Prefix: 64, | ||
RouteTarget: "2600:3c00::1", | ||
IsBGP: true, | ||
Linodes: []int{12345, 67890}, | ||
}, | ||
}, | ||
} | ||
|
||
base.MockGet("networking/ipv6/pools", mockResponse) | ||
|
||
pools, err := base.Client.ListIPv6Pools(context.Background(), nil) | ||
|
||
assert.NoError(t, err, "Expected no error when listing IPv6 pools") | ||
assert.NotNil(t, pools, "Expected non-nil IPv6 pools response") | ||
assert.Len(t, pools, 1, "Expected one IPv6 pool in response") | ||
assert.Equal(t, "2600:3c00::/64", pools[0].Range, "Expected matching IPv6 range") | ||
assert.Equal(t, "us-east", pools[0].Region, "Expected matching region") | ||
assert.Equal(t, 64, pools[0].Prefix, "Expected matching prefix length") | ||
assert.Equal(t, "2600:3c00::1", pools[0].RouteTarget, "Expected matching route target") | ||
assert.True(t, pools[0].IsBGP, "Expected IsBGP to be true") | ||
assert.ElementsMatch(t, []int{12345, 67890}, pools[0].Linodes, "Expected matching Linodes list") | ||
} | ||
|
||
func TestIPIPv6Pool_Get(t *testing.T) { | ||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
id := "1" | ||
mockResponse := linodego.IPv6Range{ | ||
Range: "2600:3c00::/64", | ||
Region: "us-east", | ||
Prefix: 64, | ||
RouteTarget: "2600:3c00::1", | ||
IsBGP: false, | ||
Linodes: []int{54321}, | ||
} | ||
base.MockGet("networking/ipv6/pools/"+id, mockResponse) | ||
|
||
pool, err := base.Client.GetIPv6Pool(context.Background(), id) | ||
assert.NoError(t, err, "Expected no error when getting IPv6 pool") | ||
assert.NotNil(t, pool, "Expected non-nil IPv6 pool response") | ||
assert.Equal(t, "2600:3c00::/64", pool.Range, "Expected matching IPv6 range") | ||
assert.Equal(t, "us-east", pool.Region, "Expected matching region") | ||
assert.Equal(t, 64, pool.Prefix, "Expected matching prefix length") | ||
assert.Equal(t, "2600:3c00::1", pool.RouteTarget, "Expected matching route target") | ||
assert.False(t, pool.IsBGP, "Expected IsBGP to be false") | ||
assert.ElementsMatch(t, []int{54321}, pool.Linodes, "Expected matching Linodes list") | ||
} |
Oops, something went wrong.