More technical debt payoff.
Applied refactoring across the entire acceptance test code base.
diff --git a/acceptance/08-reauthentication.go b/acceptance/08-reauthentication.go
index 8b198c7..b15e5e0 100644
--- a/acceptance/08-reauthentication.go
+++ b/acceptance/08-reauthentication.go
@@ -10,56 +10,39 @@
var rgn = flag.String("r", "DFW", "Datacenter region to interrogate.")
func main() {
- provider, username, password := getCredentials()
flag.Parse()
- // Authenticate initially against the service.
- auth, err := gophercloud.Authenticate(
- provider,
- gophercloud.AuthOptions{
- Username: username,
- Password: password,
- AllowReauth: true, // This enables reauthentication.
- },
- )
- if err != nil {
- panic(err)
- }
+ // Invoke withIdentity such that re-auth is enabled.
+ withIdentity(true, func(auth gophercloud.AccessProvider) {
+ token1 := auth.AuthToken()
- // Cache our initial authentication token.
- token1 := auth.AuthToken()
+ withServerApi(auth, func(servers gophercloud.CloudServersProvider) {
+ // Just to confirm everything works, we should be able to list images without error.
+ _, err := servers.ListImages()
+ if err != nil {
+ panic(err)
+ }
- // Acquire access to the cloud servers API.
- servers, err := gophercloud.ServersApi(auth, gophercloud.ApiCriteria{
- Name: "cloudServersOpenStack",
- Region: *rgn,
- VersionId: "2",
- UrlChoice: gophercloud.PublicURL,
+ // Revoke our current authentication token.
+ auth.Revoke(auth.AuthToken())
+
+ // Attempt to list images again. This should _succeed_, because we enabled re-authentication.
+ _, err = servers.ListImages()
+ if err != nil {
+ panic(err)
+ }
+
+ // However, our new authentication token should differ.
+ token2 := auth.AuthToken()
+
+ if !*quiet {
+ fmt.Println("Old authentication token: ", token1)
+ fmt.Println("New authentication token: ", token2)
+ }
+
+ if token1 == token2 {
+ panic("Tokens should differ")
+ }
+ })
})
- if err != nil {
- panic(err)
- }
-
- // Just to confirm everything works, we should be able to list images without error.
- _, err = servers.ListImages()
- if err != nil {
- panic(err)
- }
-
- // Revoke our current authentication token.
- auth.Revoke(auth.AuthToken())
-
- // Attempt to list images again. This should _succeed_, because we enabled re-authentication.
- _, err = servers.ListImages()
- if err != nil {
- panic(err)
- }
-
- // However, our new authentication token should differ.
- token2 := auth.AuthToken()
-
- if !*quiet {
- fmt.Println("Old authentication token: ", token1)
- fmt.Println("New authentication token: ", token2)
- }
}