QuotaSets Acceptance Test Cleanup
The following changes were made to the quota sets acceptance tests:
* Added build tag.
* Renamed tests so tests can selectively be run by substring.
* Now obtaining identityclient via common compute acctest function.
diff --git a/acceptance/openstack/compute/v2/quotaset_test.go b/acceptance/openstack/compute/v2/quotaset_test.go
index d7883df..60b8563 100644
--- a/acceptance/openstack/compute/v2/quotaset_test.go
+++ b/acceptance/openstack/compute/v2/quotaset_test.go
@@ -1,60 +1,69 @@
-// +build acceptance compute
+// +build acceptance compute quotasets
package v2
import (
+ "fmt"
"testing"
"github.com/gophercloud/gophercloud"
- "github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets"
"github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
- "github.com/gophercloud/gophercloud/pagination"
- th "github.com/gophercloud/gophercloud/testhelper"
)
-func TestGetQuotaset(t *testing.T) {
+func TestQuotasetGet(t *testing.T) {
client, err := newClient()
if err != nil {
t.Fatalf("Unable to create a compute client: %v", err)
}
- idclient := openstack.NewIdentityV2(client.ProviderClient)
- quotaset, err := quotasets.Get(client, findTenant(t, idclient)).Extract()
+ identityClient, err := newIdentityClient()
+ if err != nil {
+ t.Fatalf("Unable to get a new identity client: %v", err)
+ }
+
+ tenantID, err := getTenantID(t, identityClient)
if err != nil {
t.Fatal(err)
}
- t.Logf("QuotaSet details:\n")
- t.Logf(" instances=[%d]\n", quotaset.Instances)
- t.Logf(" cores=[%d]\n", quotaset.Cores)
- t.Logf(" ram=[%d]\n", quotaset.Ram)
- t.Logf(" key_pairs=[%d]\n", quotaset.KeyPairs)
- t.Logf(" metadata_items=[%d]\n", quotaset.MetadataItems)
- t.Logf(" security_groups=[%d]\n", quotaset.SecurityGroups)
- t.Logf(" security_group_rules=[%d]\n", quotaset.SecurityGroupRules)
- t.Logf(" fixed_ips=[%d]\n", quotaset.FixedIps)
- t.Logf(" floating_ips=[%d]\n", quotaset.FloatingIps)
- t.Logf(" injected_file_content_bytes=[%d]\n", quotaset.InjectedFileContentBytes)
- t.Logf(" injected_file_path_bytes=[%d]\n", quotaset.InjectedFilePathBytes)
- t.Logf(" injected_files=[%d]\n", quotaset.InjectedFiles)
+ quotaSet, err := quotasets.Get(client, tenantID).Extract()
+ if err != nil {
+ t.Fatal(err)
+ }
+ printQuotaSet(t, quotaSet)
}
-func findTenant(t *testing.T, client *gophercloud.ServiceClient) string {
- var tenantID string
- err := tenants.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
- tenantList, err := tenants.ExtractTenants(page)
- th.AssertNoErr(t, err)
+func getTenantID(t *testing.T, client *gophercloud.ServiceClient) (string, error) {
+ allPages, err := tenants.List(client, nil).AllPages()
+ if err != nil {
+ t.Fatalf("Unable to get list of tenants: %v", err)
+ }
- for _, t := range tenantList {
- tenantID = t.ID
- break
- }
+ allTenants, err := tenants.ExtractTenants(allPages)
+ if err != nil {
+ t.Fatalf("Unable to extract tenants: %v", err)
+ }
- return true, nil
- })
- th.AssertNoErr(t, err)
+ for _, tenant := range allTenants {
+ return tenant.ID, nil
+ }
- return tenantID
+ return "", fmt.Errorf("Unable to get tenant ID")
+}
+
+func printQuotaSet(t *testing.T, quotaSet *quotasets.QuotaSet) {
+ t.Logf("instances: %d\n", quotaSet.Instances)
+ t.Logf("cores: %d\n", quotaSet.Cores)
+ t.Logf("ram: %d\n", quotaSet.Ram)
+ t.Logf("key_pairs: %d\n", quotaSet.KeyPairs)
+ t.Logf("metadata_items: %d\n", quotaSet.MetadataItems)
+ t.Logf("security_groups: %d\n", quotaSet.SecurityGroups)
+ t.Logf("security_group_rules: %d\n", quotaSet.SecurityGroupRules)
+ t.Logf("fixed_ips: %d\n", quotaSet.FixedIps)
+ t.Logf("floating_ips: %d\n", quotaSet.FloatingIps)
+ t.Logf("injected_file_content_bytes: %d\n", quotaSet.InjectedFileContentBytes)
+ t.Logf("injected_file_path_bytes: %d\n", quotaSet.InjectedFilePathBytes)
+ t.Logf("injected_files: %d\n", quotaSet.InjectedFiles)
}