-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat.] RMS query endpoints and tests
- Loading branch information
1 parent
4af12d2
commit 8b82ce2
Showing
17 changed files
with
809 additions
and
1 deletion.
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
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,186 @@ | ||
package v1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" | ||
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/rms/query" | ||
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" | ||
) | ||
|
||
func TestSpecificResourceTypeList(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.ListSpecificOpts{} | ||
resources, err := query.ListSpecificType( | ||
client, | ||
client.DomainID, | ||
"ecs", | ||
"cloudservers", | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
tools.AssertLengthGreaterThan(t, resources, 1) | ||
} | ||
|
||
func TestRecorderResourceList(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.ListRecordedOpts{} | ||
resources, err := query.ListRecordedResources( | ||
client, | ||
client.DomainID, | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, 0, len(resources)) | ||
} | ||
|
||
func TestServicesList(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.ListServicesOpts{} | ||
resources, err := query.ListServices( | ||
client, | ||
client.DomainID, | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
tools.AssertLengthGreaterThan(t, resources, 1) | ||
} | ||
|
||
func TestGetSpecificByIdResource(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.ListSpecificOpts{} | ||
resources, err := query.ListSpecificType( | ||
client, | ||
client.DomainID, | ||
"ecs", | ||
"cloudservers", | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
if len(resources) != 0 { | ||
res, err := query.GetResource( | ||
client, | ||
client.DomainID, | ||
"ecs", | ||
"cloudservers", | ||
resources[0].ID, | ||
) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, resources[0].ID, res.ID) | ||
} | ||
} | ||
|
||
func TestRecordedResourcesTagsList(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.ListRecordedTagsOpts{} | ||
resources, err := query.ListRecordedResourcesTags( | ||
client, | ||
client.DomainID, | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, 0, len(resources)) | ||
} | ||
|
||
func TestRecordedResourcesSummaryList(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.ListRecordedSummaryOpts{} | ||
resources, err := query.ListRecordedResourcesSummary( | ||
client, | ||
client.DomainID, | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, 0, len(resources)) | ||
} | ||
|
||
func TestAllResourcesList(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.ListAllOpts{} | ||
resources, err := query.ListAllResources( | ||
client, | ||
client.DomainID, | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
tools.AssertLengthGreaterThan(t, resources, 1) | ||
} | ||
|
||
func TestAnyResourceById(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.ListAllOpts{} | ||
resources, err := query.ListAllResources( | ||
client, | ||
client.DomainID, | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
if len(resources) != 0 { | ||
res, err := query.GetAnyResource( | ||
client, | ||
client.DomainID, | ||
resources[0].ID, | ||
) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, resources[0].ID, res.ID) | ||
} | ||
} | ||
|
||
func TestGetTagsFromAnyResource(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.ListAllTagsOpts{} | ||
tags, err := query.ListAllResourcesTags( | ||
client, | ||
client.DomainID, | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
tools.AssertLengthGreaterThan(t, tags, 1) | ||
} | ||
|
||
func TestGetCountResources(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.CountOpts{} | ||
count, err := query.GetCount( | ||
client, | ||
client.DomainID, | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
tools.PrintResource(t, count) | ||
} | ||
|
||
func TestResourcesSummaryList(t *testing.T) { | ||
client, err := clients.NewRMSClient() | ||
th.AssertNoErr(t, err) | ||
|
||
listOpts := query.ListSummaryOpts{} | ||
resources, err := query.ListResourcesSummary( | ||
client, | ||
client.DomainID, | ||
listOpts, | ||
) | ||
th.AssertNoErr(t, err) | ||
tools.AssertLengthGreaterThan(t, resources, 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
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
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
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,20 @@ | ||
package query | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
func GetAnyResource(client *golangsdk.ServiceClient, domainId, id string) (*Resource, error) { | ||
// GET /v1/resource-manager/domains/{domain_id}/all-resources/{resource_id} | ||
raw, err := client.Get(client.ServiceURL( | ||
"resource-manager", "domains", domainId, | ||
"all-resources", id), nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res Resource | ||
err = extract.Into(raw.Body, &res) | ||
return &res, err | ||
} |
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,42 @@ | ||
package query | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
type CountOpts struct { | ||
// Specifies the region ID. | ||
RegionId string `q:"region_id"` | ||
// Specifies the project ID. | ||
ProjectId string `q:"project_id"` | ||
// Specifies the resource type | ||
Type string `q:"type"` | ||
// Specifies the resource ID. | ||
Id string `q:"id"` | ||
// Specifies the resource name. | ||
Name string `q:"name"` | ||
// Specifies tags. The format is key or key=value. | ||
Tags []string `q:"tags"` | ||
} | ||
|
||
func GetCount(client *golangsdk.ServiceClient, domainId string, opts CountOpts) (*int, error) { | ||
// GET /v1/resource-manager/domains/{domain_id}/all-resources/count | ||
url, err := golangsdk.NewURLBuilder(). | ||
WithEndpoints("resource-manager", "domains", domainId, "all-resources", "count"). | ||
WithQueryParams(&opts).Build() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
raw, err := client.Get(client.ServiceURL(url.String()), nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res struct { | ||
Count int `json:"total_count"` | ||
} | ||
err = extract.Into(raw.Body, &res) | ||
return &res.Count, err | ||
} |
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,20 @@ | ||
package query | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
func GetRecordedResource(client *golangsdk.ServiceClient, domainId, id string) (*Resource, error) { | ||
// GET /v1/resource-manager/domains/{domain_id}/tracked-resources/{resource_id} | ||
raw, err := client.Get(client.ServiceURL( | ||
"resource-manager", "domains", domainId, | ||
"tracked-resources", id), nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res Resource | ||
err = extract.Into(raw.Body, &res) | ||
return &res, err | ||
} |
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,20 @@ | ||
package query | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
func GetResource(client *golangsdk.ServiceClient, domainId, service, resourceType, id string) (*Resource, error) { | ||
// GET /v1/resource-manager/domains/{domain_id}/provider/{provider}/type/{type}/resources/{resource_id} | ||
raw, err := client.Get(client.ServiceURL( | ||
"resource-manager", "domains", domainId, | ||
"provider", service, "type", resourceType, "resources", id), nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res Resource | ||
err = extract.Into(raw.Body, &res) | ||
return &res, err | ||
} |
Oops, something went wrong.