Acceptance test for v2 token generation.
diff --git a/acceptance/openstack/identity/v2/identity_test.go b/acceptance/openstack/identity/v2/identity_test.go
deleted file mode 100644
index ff4c9cd..0000000
--- a/acceptance/openstack/identity/v2/identity_test.go
+++ /dev/null
@@ -1,114 +0,0 @@
-// +build acceptance
-
-package v2
-
-import (
- "fmt"
- "os"
- "testing"
- "text/tabwriter"
-
- "github.com/rackspace/gophercloud"
- identity "github.com/rackspace/gophercloud/openstack/identity/v2"
- "github.com/rackspace/gophercloud/openstack/utils"
-)
-
-type extractor func(*identity.Token) string
-
-func TestAuthentication(t *testing.T) {
- // Create an initialized set of authentication options based on available OS_*
- // environment variables.
- ao, err := utils.AuthOptions()
- if err != nil {
- t.Error(err)
- return
- }
-
- // Attempt to authenticate with them.
- client := &gophercloud.ServiceClient{Endpoint: ao.IdentityEndpoint + "/"}
- r, err := identity.Authenticate(client, ao)
- if err != nil {
- t.Error(err)
- return
- }
-
- // We're authenticated; now let's grab our authentication token.
- tok, err := identity.GetToken(r)
- if err != nil {
- t.Error(err)
- return
- }
-
- // Authentication tokens have a variety of fields which might be of some interest.
- // Let's print a few of them out.
- table := map[string]extractor{
- "ID": func(t *identity.Token) string { return tok.ID },
- "Expires": func(t *identity.Token) string { return tok.Expires },
- }
-
- for attr, fn := range table {
- fmt.Printf("Your token's %s is %s\n", attr, fn(tok))
- }
-
- // With each authentication, you receive a master directory of all the services
- // your account can access. This "service catalog", as OpenStack calls it,
- // provides you the means to exploit other OpenStack services.
- sc, err := identity.GetServiceCatalog(r)
- if err != nil {
- t.Error(err)
- return
- }
-
- // Prepare our elastic tabstopped writer for our table.
- w := new(tabwriter.Writer)
- w.Init(os.Stdout, 2, 8, 2, ' ', 0)
-
- // Different providers will provide different services. Let's print them
- // in summary.
- ces, err := sc.CatalogEntries()
- fmt.Println("Service Catalog Summary:")
- fmt.Fprintln(w, "Name\tType\t")
- for _, ce := range ces {
- fmt.Fprintf(w, "%s\t%s\t\n", ce.Name, ce.Type)
- }
- w.Flush()
-
- // Now let's print them in greater detail.
- for _, ce := range ces {
- fmt.Printf("Endpoints for %s/%s\n", ce.Name, ce.Type)
- fmt.Fprintln(w, "Version\tRegion\tTenant\tPublic URL\tInternal URL\t")
- for _, ep := range ce.Endpoints {
- fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t\n", ep.VersionID, ep.Region, ep.TenantID, ep.PublicURL, ep.InternalURL)
- }
- w.Flush()
- }
-}
-
-func TestExtensions(t *testing.T) {
- // Create an initialized set of authentication options based on available OS_*
- // environment variables.
- ao, err := utils.AuthOptions()
- if err != nil {
- t.Error(err)
- return
- }
-
- // Attempt to query extensions.
- client := &gophercloud.ServiceClient{Endpoint: ao.IdentityEndpoint + "/"}
- exts, err := identity.GetExtensions(client, ao)
- if err != nil {
- t.Error(err)
- return
- }
-
- // Print out a summary of supported extensions
- aliases, err := exts.Aliases()
- if err != nil {
- t.Error(err)
- return
- }
- fmt.Println("Extension Aliases:")
- for _, alias := range aliases {
- fmt.Printf(" %s\n", alias)
- }
-}
diff --git a/acceptance/openstack/identity/v2/pkg.go b/acceptance/openstack/identity/v2/pkg.go
new file mode 100644
index 0000000..5ec3cc8
--- /dev/null
+++ b/acceptance/openstack/identity/v2/pkg.go
@@ -0,0 +1 @@
+package v2
diff --git a/acceptance/openstack/identity/v2/token_test.go b/acceptance/openstack/identity/v2/token_test.go
new file mode 100644
index 0000000..3f37a27
--- /dev/null
+++ b/acceptance/openstack/identity/v2/token_test.go
@@ -0,0 +1,54 @@
+// +build acceptance
+
+package v2
+
+import (
+ "testing"
+
+ "github.com/rackspace/gophercloud/openstack"
+ tokens2 "github.com/rackspace/gophercloud/openstack/identity/v2/tokens"
+ "github.com/rackspace/gophercloud/openstack/utils"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+func TestAuthenticate(t *testing.T) {
+ // 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 = ""
+ }
+
+ // Create an unauthenticated client.
+ provider, err := openstack.NewClient(ao.IdentityEndpoint)
+ th.AssertNoErr(t, err)
+
+ // Create a service client.
+ service := openstack.NewIdentityV2(provider)
+
+ // 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("[%d]: name=[%s], type=[%s]", i, entry.Name, entry.Type)
+ for _, endpoint := range entry.Endpoints {
+ t.Logf(" - region=[%s] publicURL=[%s]", endpoint.Region, endpoint.PublicURL)
+ }
+ }
+}