-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
431 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,21 @@ | ||
{ | ||
"id": 123, | ||
"label": "test-vpc", | ||
"description": "Test VPC description", | ||
"region": "us-east", | ||
"subnets": [ | ||
{ | ||
"id": 1, | ||
"label": "subnet-1", | ||
"region": "us-east" | ||
}, | ||
{ | ||
"id": 2, | ||
"label": "subnet-2", | ||
"region": "us-east" | ||
} | ||
], | ||
"created": "2023-01-01T12:00:00", | ||
"updated": "2023-01-02T12:00:00" | ||
} | ||
|
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 @@ | ||
{ | ||
"id": 123, | ||
"label": "test-vpc", | ||
"description": "Test VPC description", | ||
"region": "us-east", | ||
"subnets": [], | ||
"created": "2023-01-01T12:00:00", | ||
"updated": "2023-01-02T12:00:00" | ||
} |
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": [ | ||
{ | ||
"address": "192.168.1.10", | ||
"vpc_id": 123 | ||
}, | ||
{ | ||
"address": "192.168.1.11", | ||
"vpc_id": 124 | ||
} | ||
], | ||
"page": 1, | ||
"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,21 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"id": 123, | ||
"label": "test-vpc", | ||
"description": "Test VPC description", | ||
"region": "us-east", | ||
"subnets": [ | ||
{ | ||
"id": 456, | ||
"label": "subnet-1", | ||
"ipv4": "192.168.1.0/24", | ||
"linodes": [] | ||
} | ||
] | ||
} | ||
], | ||
"page": 1, | ||
"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,15 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"address": "192.168.1.20", | ||
"vpc_id": 123 | ||
}, | ||
{ | ||
"address": "192.168.1.21", | ||
"vpc_id": 123 | ||
} | ||
], | ||
"page": 1, | ||
"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 @@ | ||
{ | ||
"id": 789, | ||
"label": "Test Subnet", | ||
"ipv4": "192.168.1.0/24", | ||
"linodes": [], | ||
"created": "2025-01-01T12:00:00", | ||
"updated": "2025-01-01T12:00:00" | ||
} |
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,22 @@ | ||
{ | ||
"id": 456, | ||
"label": "Existing Subnet", | ||
"ipv4": "192.168.2.0/24", | ||
"linodes": [ | ||
{ | ||
"id": 101, | ||
"interfaces": [ | ||
{ | ||
"id": 1, | ||
"active": true | ||
}, | ||
{ | ||
"id": 2, | ||
"active": false | ||
} | ||
] | ||
} | ||
], | ||
"created": "2025-01-01T10:00:00", | ||
"updated": "2025-01-02T10:00:00" | ||
} |
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 @@ | ||
{ | ||
"id": 456, | ||
"label": "Updated Subnet", | ||
"ipv4": "192.168.2.0/24", | ||
"linodes": [], | ||
"created": "2025-01-01T10:00:00", | ||
"updated": "2025-02-01T10:00:00" | ||
} |
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,17 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"id": 123, | ||
"label": "Subnet A", | ||
"ipv4": "192.168.3.0/24" | ||
}, | ||
{ | ||
"id": 124, | ||
"label": "Subnet B", | ||
"ipv4": "192.168.4.0/24" | ||
} | ||
], | ||
"page": 1, | ||
"pages": 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 @@ | ||
{ | ||
"id": 123, | ||
"label": "updated-vpc", | ||
"description": "Updated description", | ||
"region": "us-east", | ||
"subnets": [], | ||
"created": "2023-01-01T12:00:00", | ||
"updated": "2023-01-02T12:00:00" | ||
} |
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,52 @@ | ||
package unit | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/linode/linodego" | ||
) | ||
|
||
func TestVPCListAllIPAddresses(t *testing.T) { | ||
fixtureData, err := fixtures.GetFixture("vpc_ips_list") | ||
assert.NoError(t, err) | ||
|
||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
// Mock the GET response with fixture data | ||
base.MockGet("vpcs/ips", fixtureData) | ||
|
||
vpcIPs, err := base.Client.ListAllVPCIPAddresses(context.Background(), &linodego.ListOptions{}) | ||
assert.NoError(t, err) | ||
|
||
assert.NotEmpty(t, vpcIPs, "Expected non-empty VPC IP addresses list") | ||
|
||
assert.NotNil(t, vpcIPs[0].Address, "Expected IP address to be non-nil") | ||
assert.Equal(t, "192.168.1.10", *vpcIPs[0].Address, "Expected IP address to match") | ||
assert.Equal(t, 123, vpcIPs[0].VPCID, "Expected VPC ID to match") | ||
} | ||
|
||
func TestVPCListSpecificIPAddresses(t *testing.T) { | ||
fixtureData, err := fixtures.GetFixture("vpc_specific_ips_list") | ||
assert.NoError(t, err) | ||
|
||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
// Mock the GET response for a specific VPC | ||
vpcID := 123 | ||
base.MockGet("vpcs/123/ips", fixtureData) | ||
|
||
vpcIPs, err := base.Client.ListVPCIPAddresses(context.Background(), vpcID, &linodego.ListOptions{}) | ||
assert.NoError(t, err) | ||
|
||
assert.NotEmpty(t, vpcIPs, "Expected non-empty VPC IP addresses list for the specified VPC") | ||
|
||
assert.NotNil(t, vpcIPs[0].Address, "Expected IP address to be non-nil") | ||
assert.Equal(t, "192.168.1.20", *vpcIPs[0].Address, "Expected IP address to match") | ||
assert.Equal(t, vpcID, vpcIPs[0].VPCID, "Expected VPC ID to match") | ||
} |
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,106 @@ | ||
package unit | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/linode/linodego" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestVPCCreateSubnet(t *testing.T) { | ||
fixtureData, err := fixtures.GetFixture("vpc_subnet_create") | ||
assert.NoError(t, err) | ||
|
||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
// Mock the POST request with the fixture response | ||
base.MockPost("vpcs/123/subnets", fixtureData) | ||
|
||
subnetCreateOpts := linodego.VPCSubnetCreateOptions{ | ||
Label: "Test Subnet", | ||
IPv4: "192.168.1.0/24", | ||
} | ||
subnet, err := base.Client.CreateVPCSubnet(context.Background(), subnetCreateOpts, 123) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, 789, subnet.ID, "Expected subnet ID to match") | ||
assert.Equal(t, "Test Subnet", subnet.Label, "Expected subnet label to match") | ||
assert.Equal(t, "192.168.1.0/24", subnet.IPv4, "Expected subnet IPv4 to match") | ||
} | ||
|
||
func TestVPCGetSubnet(t *testing.T) { | ||
fixtureData, err := fixtures.GetFixture("vpc_subnet_get") | ||
assert.NoError(t, err) | ||
|
||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
// Mock the GET request with the fixture response | ||
base.MockGet("vpcs/123/subnets/456", fixtureData) | ||
|
||
subnet, err := base.Client.GetVPCSubnet(context.Background(), 123, 456) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, 456, subnet.ID, "Expected subnet ID to match") | ||
assert.Equal(t, "Existing Subnet", subnet.Label, "Expected subnet label to match") | ||
assert.Equal(t, "192.168.2.0/24", subnet.IPv4, "Expected subnet IPv4 to match") | ||
assert.Equal(t, 101, subnet.Linodes[0].ID, "Expected Linode ID to match") | ||
assert.True(t, subnet.Linodes[0].Interfaces[0].Active, "Expected interface to be active") | ||
} | ||
|
||
func TestVPCListSubnets(t *testing.T) { | ||
fixtureData, err := fixtures.GetFixture("vpc_subnets_list") | ||
assert.NoError(t, err) | ||
|
||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
// Mock the GET request with the fixture response | ||
base.MockGet("vpcs/123/subnets", fixtureData) | ||
|
||
subnets, err := base.Client.ListVPCSubnets(context.Background(), 123, &linodego.ListOptions{}) | ||
assert.NoError(t, err, "Expected no error when listing subnets") | ||
assert.Len(t, subnets, 2, "Expected two subnets in the list") | ||
|
||
assert.Equal(t, 123, subnets[0].ID, "Expected first subnet ID to match") | ||
assert.Equal(t, "Subnet A", subnets[0].Label, "Expected first subnet label to match") | ||
assert.Equal(t, "192.168.3.0/24", subnets[0].IPv4, "Expected first subnet IPv4 to match") | ||
} | ||
|
||
func TestVPCUpdateSubnet(t *testing.T) { | ||
fixtureData, err := fixtures.GetFixture("vpc_subnet_update") | ||
assert.NoError(t, err) | ||
|
||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
// Mock the PUT request with the fixture response | ||
base.MockPut("vpcs/123/subnets/456", fixtureData) | ||
|
||
subnetUpdateOpts := linodego.VPCSubnetUpdateOptions{ | ||
Label: "Updated Subnet", | ||
} | ||
subnet, err := base.Client.UpdateVPCSubnet(context.Background(), 123, 456, subnetUpdateOpts) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, 456, subnet.ID, "Expected subnet ID to match") | ||
assert.Equal(t, "Updated Subnet", subnet.Label, "Expected subnet label to match") | ||
} | ||
|
||
func TestVPCDeleteSubnet(t *testing.T) { | ||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
// Mock the DELETE request | ||
base.MockDelete("vpcs/123/subnets/456",nil) | ||
|
||
err := base.Client.DeleteVPCSubnet(context.Background(), 123, 456) | ||
assert.NoError(t, err,"Expected no error when deleting VPCSubnet") | ||
} |
Oops, something went wrong.