-
Notifications
You must be signed in to change notification settings - Fork 99
Add unit test coverage for Type, Vlan and Tag related methods/functions #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8a67446
types_unit_tests
vshanthe 85c7bc3
vlan_tests
vshanthe cda5f7a
unit_test_tag
vshanthe 5d8309a
address_PR_comments
vshanthe 836d77f
fix
vshanthe 3812281
resolve_merge_conflict
vshanthe 7a16eb7
Merge branch 'main' into types_tests
vshanthe 0b50956
fix lint
vshanthe 3cce228
Merge branch 'main' into types_tests
vshanthe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| go 1.22 | ||
| go 1.22.0 | ||
|
|
||
| use ( | ||
| . | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,26 @@ | ||
| { | ||
| "id": "g6-standard-2", | ||
| "disk": 4000, | ||
| "class": "standard", | ||
| "price": { | ||
| "hourly": 0.015, | ||
| "monthly": 10 | ||
| }, | ||
| "label": "Linode 2GB", | ||
| "addons": { | ||
| "backups": { | ||
| "price": { | ||
| "hourly": 0.003, | ||
| "monthly": 2 | ||
| }, | ||
| "region_prices": [] | ||
| } | ||
| }, | ||
| "region_prices": [], | ||
| "network_out": 2000, | ||
| "memory": 4000, | ||
| "transfer": 500, | ||
| "vcpus": 2, | ||
| "gpus": 0, | ||
| "successor": null | ||
| } |
This file contains hidden or 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,44 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "id": "g6-nanode-1", | ||
| "disk": 25600, | ||
| "class": "nanode", | ||
| "price": { | ||
| "hourly": 0.0075, | ||
| "monthly": 5 | ||
| }, | ||
| "label": "Nanode 1GB", | ||
| "addons": null, | ||
| "region_prices": [], | ||
| "network_out": 1000, | ||
| "memory": 1024, | ||
| "transfer": 250, | ||
| "vcpus": 1, | ||
| "gpus": 0, | ||
| "successor": null | ||
| }, | ||
| { | ||
| "id": "g6-standard-2", | ||
| "disk": 51200, | ||
| "class": "standard", | ||
| "price": { | ||
| "hourly": 0.015, | ||
| "monthly": 10 | ||
| }, | ||
| "label": "Linode 2GB", | ||
| "addons": null, | ||
| "region_prices": [], | ||
| "network_out": 2000, | ||
| "memory": 2048, | ||
| "transfer": 500, | ||
| "vcpus": 2, | ||
| "gpus": 0, | ||
| "successor": null | ||
| } | ||
| ], | ||
| "page": 1, | ||
| "pages": 1, | ||
| "results": 2 | ||
| } | ||
|
|
This file contains hidden or 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,3 @@ | ||
| { | ||
| "label": "new-tag" | ||
| } |
This file contains hidden or 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": [ | ||
| { | ||
| "type": "linode", | ||
| "data": { | ||
| "id": 12345, | ||
| "label": "example-instance", | ||
| "region": "us-east" | ||
| } | ||
| } | ||
| ], | ||
| "page": 1, | ||
| "pages": 1, | ||
| "results": 1 | ||
| } |
This file contains hidden or 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,10 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "label": "example-tag" | ||
| } | ||
| ], | ||
| "page": 1, | ||
| "pages": 1, | ||
| "results": 1 | ||
| } |
This file contains hidden or 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": [ | ||
| { | ||
| "interfaces": [ | ||
| { | ||
| "label": "test-vlan", | ||
| "ipam_address": "10.0.0.1/24" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "page": 1, | ||
| "pages": 1, | ||
| "results": 1 | ||
| } |
This file contains hidden or 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,13 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "label": "test-vlan", | ||
| "linodes": [12345], | ||
| "region": "us-east", | ||
| "created": "2024-12-01T12:00:00" | ||
| } | ||
| ], | ||
| "page": 1, | ||
| "pages": 1, | ||
| "results": 1 | ||
| } |
This file contains hidden or 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,122 @@ | ||
| package unit | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/linode/linodego" | ||
| "github.com/stretchr/testify/assert" | ||
| "golang.org/x/exp/slices" | ||
| ) | ||
|
|
||
| func TestListTags(t *testing.T) { | ||
| // Load the fixture data for tags | ||
| fixtureData, err := fixtures.GetFixture("tags_list") | ||
| assert.NoError(t, err) | ||
|
|
||
| var base ClientBaseCase | ||
| base.SetUp(t) | ||
| defer base.TearDown(t) | ||
|
|
||
| base.MockGet("tags", fixtureData) | ||
|
|
||
| tags, err := base.Client.ListTags(context.Background(), &linodego.ListOptions{}) | ||
| assert.NoError(t, err) | ||
|
|
||
| assert.NotEmpty(t, tags, "Expected non-empty tag list") | ||
|
|
||
| // Check if a specific tag exists using slices.ContainsFunc | ||
| exists := slices.ContainsFunc(tags, func(tag linodego.Tag) bool { | ||
| return tag.Label == "example-tag" | ||
| }) | ||
|
|
||
| assert.True(t, exists, "Expected tag list to contain 'example-tag'") | ||
| } | ||
|
|
||
|
|
||
| func TestCreateTag(t *testing.T) { | ||
| // Load the fixture data for tag creation | ||
| fixtureData, err := fixtures.GetFixture("tag_create") | ||
| assert.NoError(t, err) | ||
|
|
||
| var base ClientBaseCase | ||
| base.SetUp(t) | ||
| defer base.TearDown(t) | ||
|
|
||
| base.MockPost("tags", fixtureData) | ||
|
|
||
| opts := linodego.TagCreateOptions{ | ||
| Label: "new-tag", | ||
| } | ||
|
|
||
| tag, err := base.Client.CreateTag(context.Background(), opts) | ||
| assert.NoError(t, err, "Expected no error when creating tag") | ||
|
|
||
| // Verify the created tag's label | ||
| assert.Equal(t, "new-tag", tag.Label, "Expected created tag label to match input") | ||
| } | ||
|
|
||
|
|
||
| func TestDeleteTag(t *testing.T) { | ||
| var base ClientBaseCase | ||
| base.SetUp(t) | ||
| defer base.TearDown(t) | ||
|
|
||
| tagLabel := "delete-tag" | ||
| base.MockDelete(fmt.Sprintf("tags/%s", tagLabel), nil) | ||
|
|
||
| err := base.Client.DeleteTag(context.Background(), tagLabel) | ||
| assert.NoError(t, err, "Expected no error when deleting tag") | ||
| } | ||
|
|
||
| func TestListTaggedObjects(t *testing.T) { | ||
| // Load the fixture data for tagged objects | ||
| fixtureData, err := fixtures.GetFixture("tagged_objects_list") | ||
| assert.NoError(t, err) | ||
|
|
||
| var base ClientBaseCase | ||
| base.SetUp(t) | ||
| defer base.TearDown(t) | ||
|
|
||
| tagLabel := "example-tag" | ||
| base.MockGet(fmt.Sprintf("tags/%s", tagLabel), fixtureData) | ||
|
|
||
| taggedObjects, err := base.Client.ListTaggedObjects(context.Background(), tagLabel, &linodego.ListOptions{}) | ||
| assert.NoError(t, err) | ||
|
|
||
| assert.NotEmpty(t, taggedObjects, "Expected non-empty tagged objects list") | ||
|
|
||
| // Find the specific tagged object using slices.IndexFunc | ||
| index := slices.IndexFunc(taggedObjects, func(obj linodego.TaggedObject) bool { | ||
| return obj.Type == "linode" | ||
| }) | ||
|
|
||
| assert.NotEqual(t, -1, index, "Expected to find a tagged object of type 'linode'") | ||
| if index != -1 { | ||
| assert.Equal(t, "linode", taggedObjects[index].Type, "Expected tagged object type to be 'linode'") | ||
| } | ||
| } | ||
|
|
||
|
|
||
| func TestSortedObjects(t *testing.T) { | ||
| // Load the fixture data for tagged objects | ||
| fixtureData, err := fixtures.GetFixture("tagged_objects_list") | ||
| assert.NoError(t, err) | ||
|
|
||
| var base ClientBaseCase | ||
| base.SetUp(t) | ||
| defer base.TearDown(t) | ||
|
|
||
| tagLabel := "example-tag" | ||
| base.MockGet(fmt.Sprintf("tags/%s", tagLabel), fixtureData) | ||
|
|
||
| taggedObjects, err := base.Client.ListTaggedObjects(context.Background(), tagLabel, &linodego.ListOptions{}) | ||
| assert.NoError(t, err) | ||
|
|
||
| sortedObjects, err := taggedObjects.SortedObjects() | ||
| assert.NoError(t, err) | ||
|
|
||
| assert.NotEmpty(t, sortedObjects.Instances, "Expected non-empty instances list in sorted objects") | ||
| assert.Equal(t, "example-instance", sortedObjects.Instances[0].Label, "Expected instance label to be 'example-instance'") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.