Convert identity acceptance tests to go test form
diff --git a/acceptance/openstack/identity/01-authenticate.go b/acceptance/openstack/identity/01-authenticate.go
deleted file mode 100644
index 59d64a4..0000000
--- a/acceptance/openstack/identity/01-authenticate.go
+++ /dev/null
@@ -1,69 +0,0 @@
-package main
-
-import (
- "fmt"
- "github.com/rackspace/gophercloud/openstack/identity"
- "github.com/rackspace/gophercloud/openstack/utils"
-)
-
-type extractor func(*identity.Token) string
-
-func main() {
- // Create an initialized set of authentication options based on available OS_*
- // environment variables.
- ao, err := utils.AuthOptions()
- if err != nil {
- panic(err)
- }
-
- // Attempt to authenticate with them.
- r, err := identity.Authenticate(ao)
- if err != nil {
- panic(err)
- }
-
- // We're authenticated; now let's grab our authentication token.
- t, err := identity.GetToken(r)
- if err != nil {
- panic(err)
- }
-
- // 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 t.Id },
- "Expires": func(t *identity.Token) string { return t.Expires },
- }
-
- for attr, fn := range table {
- fmt.Printf("Your token's %s is %s\n", attr, fn(t))
- }
-
- // 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 {
- panic(err)
- }
-
- // Different providers will provide different services. Let's print them
- // in summary.
- ces, err := sc.CatalogEntries()
- fmt.Printf("Service Catalog Summary:\n %32s %-16s\n", "Name", "Type")
- for _, ce := range ces {
- fmt.Printf(" %32s | %-16s\n", ce.Name, ce.Type)
- }
-
- // Now let's print them in greater detail.
- for _, ce := range ces {
- fmt.Printf("Endpoints for %s/%s\n", ce.Name, ce.Type)
- for _, ep := range ce.Endpoints {
- fmt.Printf(" Version: %s\n", ep.VersionId)
- fmt.Printf(" Region: %s\n", ep.Region)
- fmt.Printf(" Tenant: %s\n", ep.TenantId)
- fmt.Printf(" Public URL: %s\n", ep.PublicURL)
- fmt.Printf(" Internal URL: %s\n", ep.InternalURL)
- }
- }
-}
diff --git a/acceptance/openstack/identity/02-extensions.go b/acceptance/openstack/identity/02-extensions.go
deleted file mode 100644
index cc78e54..0000000
--- a/acceptance/openstack/identity/02-extensions.go
+++ /dev/null
@@ -1,32 +0,0 @@
-package main
-
-import (
- "fmt"
- "github.com/rackspace/gophercloud/openstack/identity"
- "github.com/rackspace/gophercloud/openstack/utils"
-)
-
-func main() {
- // Create an initialized set of authentication options based on available OS_*
- // environment variables.
- ao, err := utils.AuthOptions()
- if err != nil {
- panic(err)
- }
-
- // Attempt to query extensions.
- exts, err := identity.GetExtensions(ao)
- if err != nil {
- panic(err)
- }
-
- // Print out a summary of supported extensions
- aliases, err := exts.Aliases()
- if err != nil {
- panic(err)
- }
- fmt.Println("Extension Aliases:")
- for _, alias := range aliases {
- fmt.Printf(" %s\n", alias)
- }
-}
diff --git a/acceptance/openstack/identity_test.go b/acceptance/openstack/identity_test.go
new file mode 100644
index 0000000..edb24ab
--- /dev/null
+++ b/acceptance/openstack/identity_test.go
@@ -0,0 +1,109 @@
+package openstack
+
+import (
+ "testing"
+ "fmt"
+ "os"
+ "github.com/rackspace/gophercloud/openstack/identity"
+ "github.com/rackspace/gophercloud/openstack/utils"
+ "text/tabwriter"
+)
+
+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.
+ r, err := identity.Authenticate(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.
+ exts, err := identity.GetExtensions(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)
+ }
+}
+