Moving calls to client helper while I'm at it
diff --git a/_site/acceptance/openstack/identity/v2/extension_test.go b/_site/acceptance/openstack/identity/v2/extension_test.go
new file mode 100644
index 0000000..2b4e062
--- /dev/null
+++ b/_site/acceptance/openstack/identity/v2/extension_test.go
@@ -0,0 +1,46 @@
+// +build acceptance
+
+package v2
+
+import (
+ "testing"
+
+ extensions2 "github.com/rackspace/gophercloud/openstack/identity/v2/extensions"
+ "github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestEnumerateExtensions(t *testing.T) {
+ service := authenticatedClient(t)
+
+ t.Logf("Extensions available on this identity endpoint:")
+ count := 0
+ err := extensions2.List(service).EachPage(func(page pagination.Page) (bool, error) {
+ t.Logf("--- Page %02d ---", count)
+
+ extensions, err := extensions2.ExtractExtensions(page)
+ th.AssertNoErr(t, err)
+
+ for i, ext := range extensions {
+ t.Logf("[%02d] name=[%s] namespace=[%s]", i, ext.Name, ext.Namespace)
+ t.Logf(" alias=[%s] updated=[%s]", ext.Alias, ext.Updated)
+ t.Logf(" description=[%s]", ext.Description)
+ }
+
+ count++
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+}
+
+func TestGetExtension(t *testing.T) {
+ service := authenticatedClient(t)
+
+ ext, err := extensions2.Get(service, "OS-KSCRUD").Extract()
+ th.AssertNoErr(t, err)
+
+ th.CheckEquals(t, "OpenStack Keystone User CRUD", ext.Name)
+ th.CheckEquals(t, "http://docs.openstack.org/identity/api/ext/OS-KSCRUD/v1.0", ext.Namespace)
+ th.CheckEquals(t, "OS-KSCRUD", ext.Alias)
+ th.CheckEquals(t, "OpenStack extensions to Keystone v2.0 API enabling User Operations.", ext.Description)
+}
diff --git a/_site/acceptance/openstack/identity/v2/identity_test.go b/_site/acceptance/openstack/identity/v2/identity_test.go
new file mode 100644
index 0000000..2ecd3ca
--- /dev/null
+++ b/_site/acceptance/openstack/identity/v2/identity_test.go
@@ -0,0 +1,48 @@
+// +build acceptance
+
+package v2
+
+import (
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/openstack"
+ "github.com/rackspace/gophercloud/openstack/utils"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func v2AuthOptions(t *testing.T) gophercloud.AuthOptions {
+ // Obtain credentials from the environment.
+ ao, err := utils.AuthOptions()
+ th.AssertNoErr(t, err)
+
+ // Trim out unused fields. Prefer authentication by API key to password.
+ ao.UserID, ao.DomainID, ao.DomainName = "", "", ""
+ if ao.APIKey != "" {
+ ao.Password = ""
+ }
+
+ return ao
+}
+
+func createClient(t *testing.T, auth bool) *gophercloud.ServiceClient {
+ ao := v2AuthOptions(t)
+
+ provider, err := openstack.NewClient(ao.IdentityEndpoint)
+ th.AssertNoErr(t, err)
+
+ if auth {
+ err = openstack.AuthenticateV2(provider, ao)
+ th.AssertNoErr(t, err)
+ }
+
+ return openstack.NewIdentityV2(provider)
+}
+
+func unauthenticatedClient(t *testing.T) *gophercloud.ServiceClient {
+ return createClient(t, false)
+}
+
+func authenticatedClient(t *testing.T) *gophercloud.ServiceClient {
+ return createClient(t, true)
+}
diff --git a/_site/acceptance/openstack/identity/v2/pkg.go b/_site/acceptance/openstack/identity/v2/pkg.go
new file mode 100644
index 0000000..5ec3cc8
--- /dev/null
+++ b/_site/acceptance/openstack/identity/v2/pkg.go
@@ -0,0 +1 @@
+package v2
diff --git a/_site/acceptance/openstack/identity/v2/tenant_test.go b/_site/acceptance/openstack/identity/v2/tenant_test.go
new file mode 100644
index 0000000..2054598
--- /dev/null
+++ b/_site/acceptance/openstack/identity/v2/tenant_test.go
@@ -0,0 +1,32 @@
+// +build acceptance
+
+package v2
+
+import (
+ "testing"
+
+ tenants2 "github.com/rackspace/gophercloud/openstack/identity/v2/tenants"
+ "github.com/rackspace/gophercloud/pagination"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestEnumerateTenants(t *testing.T) {
+ service := authenticatedClient(t)
+
+ t.Logf("Tenants to which your current token grants access:")
+ count := 0
+ err := tenants2.List(service, nil).EachPage(func(page pagination.Page) (bool, error) {
+ t.Logf("--- Page %02d ---", count)
+
+ tenants, err := tenants2.ExtractTenants(page)
+ th.AssertNoErr(t, err)
+ for i, tenant := range tenants {
+ t.Logf("[%02d] name=[%s] id=[%s] description=[%s] enabled=[%v]",
+ i, tenant.Name, tenant.ID, tenant.Description, tenant.Enabled)
+ }
+
+ count++
+ return true, nil
+ })
+ th.AssertNoErr(t, err)
+}
diff --git a/_site/acceptance/openstack/identity/v2/token_test.go b/_site/acceptance/openstack/identity/v2/token_test.go
new file mode 100644
index 0000000..47381a2
--- /dev/null
+++ b/_site/acceptance/openstack/identity/v2/token_test.go
@@ -0,0 +1,38 @@
+// +build acceptance
+
+package v2
+
+import (
+ "testing"
+
+ tokens2 "github.com/rackspace/gophercloud/openstack/identity/v2/tokens"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestAuthenticate(t *testing.T) {
+ ao := v2AuthOptions(t)
+ service := unauthenticatedClient(t)
+
+ // Authenticated!
+ result := tokens2.Create(service, ao)
+
+ // Extract and print the token.
+ token, err := result.ExtractToken()
+ th.AssertNoErr(t, err)
+
+ t.Logf("Acquired token: [%s]", token.ID)
+ t.Logf("The token will expire at: [%s]", token.ExpiresAt.String())
+ t.Logf("The token is valid for tenant: [%#v]", token.Tenant)
+
+ // Extract and print the service catalog.
+ catalog, err := result.ExtractServiceCatalog()
+ th.AssertNoErr(t, err)
+
+ t.Logf("Acquired service catalog listing [%d] services", len(catalog.Entries))
+ for i, entry := range catalog.Entries {
+ t.Logf("[%02d]: name=[%s], type=[%s]", i, entry.Name, entry.Type)
+ for _, endpoint := range entry.Endpoints {
+ t.Logf(" - region=[%s] publicURL=[%s]", endpoint.Region, endpoint.PublicURL)
+ }
+ }
+}
diff --git a/_site/acceptance/openstack/identity/v3/endpoint_test.go b/_site/acceptance/openstack/identity/v3/endpoint_test.go
new file mode 100644
index 0000000..9032ec3
--- /dev/null
+++ b/_site/acceptance/openstack/identity/v3/endpoint_test.go
@@ -0,0 +1,108 @@
+// +build acceptance
+
+package v3
+
+import (
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ endpoints3 "github.com/rackspace/gophercloud/openstack/identity/v3/endpoints"
+ services3 "github.com/rackspace/gophercloud/openstack/identity/v3/services"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+func TestListEndpoints(t *testing.T) {
+ // Create a service client.
+ serviceClient := createAuthenticatedClient(t)
+ if serviceClient == nil {
+ return
+ }
+
+ // Use the service to list all available endpoints.
+ pager := endpoints3.List(serviceClient, endpoints3.ListOpts{})
+ err := pager.EachPage(func(page pagination.Page) (bool, error) {
+ t.Logf("--- Page ---")
+
+ endpoints, err := endpoints3.ExtractEndpoints(page)
+ if err != nil {
+ t.Fatalf("Error extracting endpoings: %v", err)
+ }
+
+ for _, endpoint := range endpoints {
+ t.Logf("Endpoint: %8s %10s %9s %s",
+ endpoint.ID,
+ endpoint.Availability,
+ endpoint.Name,
+ endpoint.URL)
+ }
+
+ return true, nil
+ })
+ if err != nil {
+ t.Errorf("Unexpected error while iterating endpoint pages: %v", err)
+ }
+}
+
+func TestNavigateCatalog(t *testing.T) {
+ // Create a service client.
+ client := createAuthenticatedClient(t)
+
+ var compute *services3.Service
+ var endpoint *endpoints3.Endpoint
+
+ // Discover the service we're interested in.
+ servicePager := services3.List(client, services3.ListOpts{ServiceType: "compute"})
+ err := servicePager.EachPage(func(page pagination.Page) (bool, error) {
+ part, err := services3.ExtractServices(page)
+ if err != nil {
+ return false, err
+ }
+ if compute != nil {
+ t.Fatalf("Expected one service, got more than one page")
+ return false, nil
+ }
+ if len(part) != 1 {
+ t.Fatalf("Expected one service, got %d", len(part))
+ return false, nil
+ }
+
+ compute = &part[0]
+ return true, nil
+ })
+ if err != nil {
+ t.Fatalf("Unexpected error iterating pages: %v", err)
+ }
+
+ if compute == nil {
+ t.Fatalf("No compute service found.")
+ }
+
+ // Enumerate the endpoints available for this service.
+ computePager := endpoints3.List(client, endpoints3.ListOpts{
+ Availability: gophercloud.AvailabilityPublic,
+ ServiceID: compute.ID,
+ })
+ err = computePager.EachPage(func(page pagination.Page) (bool, error) {
+ part, err := endpoints3.ExtractEndpoints(page)
+ if err != nil {
+ return false, err
+ }
+ if endpoint != nil {
+ t.Fatalf("Expected one endpoint, got more than one page")
+ return false, nil
+ }
+ if len(part) != 1 {
+ t.Fatalf("Expected one endpoint, got %d", len(part))
+ return false, nil
+ }
+
+ endpoint = &part[0]
+ return true, nil
+ })
+
+ if endpoint == nil {
+ t.Fatalf("No endpoint found.")
+ }
+
+ t.Logf("Success. The compute endpoint is at %s.", endpoint.URL)
+}
diff --git a/_site/acceptance/openstack/identity/v3/identity_test.go b/_site/acceptance/openstack/identity/v3/identity_test.go
new file mode 100644
index 0000000..e0503e2
--- /dev/null
+++ b/_site/acceptance/openstack/identity/v3/identity_test.go
@@ -0,0 +1,41 @@
+// +build acceptance
+
+package v3
+
+import (
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/openstack"
+ "github.com/rackspace/gophercloud/openstack/utils"
+)
+
+func createAuthenticatedClient(t *testing.T) *gophercloud.ServiceClient {
+ // Obtain credentials from the environment.
+ ao, err := utils.AuthOptions()
+ if err != nil {
+ t.Fatalf("Unable to acquire credentials: %v", err)
+ }
+
+ // Trim out unused fields.
+ ao.Username, ao.TenantID, ao.TenantName = "", "", ""
+
+ if ao.UserID == "" {
+ t.Logf("Skipping identity v3 tests because no OS_USERID is present.")
+ return nil
+ }
+
+ // Create a client and manually authenticate against v3.
+ providerClient, err := openstack.NewClient(ao.IdentityEndpoint)
+ if err != nil {
+ t.Fatalf("Unable to instantiate client: %v", err)
+ }
+
+ err = openstack.AuthenticateV3(providerClient, ao)
+ if err != nil {
+ t.Fatalf("Unable to authenticate against identity v3: %v", err)
+ }
+
+ // Create a service client.
+ return openstack.NewIdentityV3(providerClient)
+}
diff --git a/_site/acceptance/openstack/identity/v3/pkg.go b/_site/acceptance/openstack/identity/v3/pkg.go
new file mode 100644
index 0000000..d3b5573
--- /dev/null
+++ b/_site/acceptance/openstack/identity/v3/pkg.go
@@ -0,0 +1,2 @@
+// Package v3 contains acceptance tests for identity v3 resources.
+package v3
diff --git a/_site/acceptance/openstack/identity/v3/service_test.go b/_site/acceptance/openstack/identity/v3/service_test.go
new file mode 100644
index 0000000..082bd11
--- /dev/null
+++ b/_site/acceptance/openstack/identity/v3/service_test.go
@@ -0,0 +1,36 @@
+// +build acceptance
+
+package v3
+
+import (
+ "testing"
+
+ services3 "github.com/rackspace/gophercloud/openstack/identity/v3/services"
+ "github.com/rackspace/gophercloud/pagination"
+)
+
+func TestListServices(t *testing.T) {
+ // Create a service client.
+ serviceClient := createAuthenticatedClient(t)
+ if serviceClient == nil {
+ return
+ }
+
+ // Use the client to list all available services.
+ pager := services3.List(serviceClient, services3.ListOpts{})
+ err := pager.EachPage(func(page pagination.Page) (bool, error) {
+ parts, err := services3.ExtractServices(page)
+ if err != nil {
+ return false, err
+ }
+
+ t.Logf("--- Page ---")
+ for _, service := range parts {
+ t.Logf("Service: %32s %15s %10s %s", service.ID, service.Type, service.Name, *service.Description)
+ }
+ return true, nil
+ })
+ if err != nil {
+ t.Errorf("Unexpected error traversing pages: %v", err)
+ }
+}
diff --git a/_site/acceptance/openstack/identity/v3/token_test.go b/_site/acceptance/openstack/identity/v3/token_test.go
new file mode 100644
index 0000000..341acb7
--- /dev/null
+++ b/_site/acceptance/openstack/identity/v3/token_test.go
@@ -0,0 +1,43 @@
+// +build acceptance
+
+package v3
+
+import (
+ "testing"
+
+ "github.com/rackspace/gophercloud/openstack"
+ tokens3 "github.com/rackspace/gophercloud/openstack/identity/v3/tokens"
+ "github.com/rackspace/gophercloud/openstack/utils"
+)
+
+func TestGetToken(t *testing.T) {
+ // Obtain credentials from the environment.
+ ao, err := utils.AuthOptions()
+ if err != nil {
+ t.Fatalf("Unable to acquire credentials: %v", err)
+ }
+
+ // Trim out unused fields. Skip if we don't have a UserID.
+ ao.Username, ao.TenantID, ao.TenantName = "", "", ""
+ if ao.UserID == "" {
+ t.Logf("Skipping identity v3 tests because no OS_USERID is present.")
+ return
+ }
+
+ // Create an unauthenticated client.
+ provider, err := openstack.NewClient(ao.IdentityEndpoint)
+ if err != nil {
+ t.Fatalf("Unable to instantiate client: %v", err)
+ }
+
+ // Create a service client.
+ service := openstack.NewIdentityV3(provider)
+
+ // Use the service to create a token.
+ token, err := tokens3.Create(service, ao, nil).Extract()
+ if err != nil {
+ t.Fatalf("Unable to get token: %v", err)
+ }
+
+ t.Logf("Acquired token: %s", token.ID)
+}