Extract the new token from headers.
diff --git a/openstack/identity/v3/tokens/requests_test.go b/openstack/identity/v3/tokens/requests_test.go
index 3ac49cd..6038f96 100644
--- a/openstack/identity/v3/tokens/requests_test.go
+++ b/openstack/identity/v3/tokens/requests_test.go
@@ -26,6 +26,7 @@
testhelper.TestHeader(t, r, "Accept", "application/json")
testhelper.TestJSONRequest(t, r, requestJSON)
+ w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, `{}`)
})
@@ -234,6 +235,33 @@
`)
}
+func TestCreateExtractsTokenFromResponse(t *testing.T) {
+ setup()
+ defer teardown()
+
+ client := gophercloud.ServiceClient{
+ Endpoint: endpoint(),
+ Options: gophercloud.AuthOptions{UserID: "me", Password: "shhh"},
+ }
+
+ mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Add("X-Subject-Token", "aaa111")
+
+ w.WriteHeader(http.StatusCreated)
+ fmt.Fprintf(w, `{}`)
+ })
+
+ result, err := Create(&client, nil)
+ if err != nil {
+ t.Errorf("Create returned an error: %v", err)
+ }
+
+ token, _ := result.TokenID()
+ if token != "aaa111" {
+ t.Errorf("Expected token to be aaa111, but was %s", token)
+ }
+}
+
func TestCreateFailureEmptyAuth(t *testing.T) {
authTokenPostErr(t, gophercloud.AuthOptions{}, nil, false, ErrMissingPassword)
}