-
Notifications
You must be signed in to change notification settings - Fork 84
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
4 changed files
with
132 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,3 @@ | ||
{ | ||
"label": "new-tag" | ||
} |
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": [ | ||
{ | ||
"type": "linode", | ||
"data": { | ||
"id": 12345, | ||
"label": "example-instance", | ||
"region": "us-east" | ||
} | ||
} | ||
], | ||
"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,10 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"label": "example-tag" | ||
} | ||
], | ||
"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,104 @@ | ||
package unit | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/linode/linodego" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
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") | ||
assert.Equal(t, "example-tag", tags[0].Label, "Expected tag label to be '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") | ||
assert.Equal(t, "linode", taggedObjects[0].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'") | ||
} |