<commit_before>// +build acceptance

package openstack

import (
	"fmt"
	identity "github.com/rackspace/gophercloud/openstack/identity/v2"
	"github.com/rackspace/gophercloud/openstack/utils"
	"os"
	"testing"
	"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)<commit_msg>Update the identity v2 acceptance test.<commit_after>// +build acceptance

package openstack

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)
{'fraction_non_alphanumeric': 0.13733905579399142, 'fraction_numerical': 0.0020526217577906325, 'mean_word_length': 3.553950722175021, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3936565', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1845, 'n_words': 545}