blob: 5476271ed7eb94906990cbb264bcc642f9bc1361 [file] [log] [blame]
Ash Wilson6425a412014-08-29 12:30:35 -04001package openstack
2
3import (
Ash Wilson4dee1b82014-08-29 14:56:45 -04004 "fmt"
5 "net/http"
Ash Wilson6425a412014-08-29 12:30:35 -04006 "testing"
7
Ash Wilson4dee1b82014-08-29 14:56:45 -04008 "github.com/rackspace/gophercloud"
Ash Wilson6425a412014-08-29 12:30:35 -04009 "github.com/rackspace/gophercloud/testhelper"
10)
11
Ash Wilson4dee1b82014-08-29 14:56:45 -040012func TestNewClientV3(t *testing.T) {
Ash Wilson6425a412014-08-29 12:30:35 -040013 testhelper.SetupHTTP()
14 defer testhelper.TeardownHTTP()
Ash Wilson4dee1b82014-08-29 14:56:45 -040015
16 const ID = "0123456789"
17
18 testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
19 fmt.Fprintf(w, `
20 {
21 "versions": {
22 "values": [
23 {
24 "status": "stable",
25 "id": "v3.0",
26 "links": [
27 { "href": "%s", "rel": "self" }
28 ]
29 },
30 {
31 "status": "stable",
32 "id": "v2.0",
33 "links": [
34 { "href": "%s", "rel": "self" }
35 ]
36 }
37 ]
38 }
39 }
40 `, testhelper.Endpoint()+"v3/", testhelper.Endpoint()+"v2.0/")
41 })
42
43 testhelper.Mux.HandleFunc("/v3/auth/tokens", func(w http.ResponseWriter, r *http.Request) {
44 w.Header().Add("X-Subject-Token", ID)
45
46 w.WriteHeader(http.StatusCreated)
47 fmt.Fprintf(w, `{ "token": { "expires_at": "2013-02-02T18:30:59.000000Z" } }`)
48 })
49
50 options := gophercloud.AuthOptions{
51 UserID: "me",
52 Password: "secret",
53 IdentityEndpoint: testhelper.Endpoint(),
54 }
55 client, err := NewClient(options)
56
57 if err != nil {
58 t.Fatalf("Unexpected error from NewClient: %s", err)
59 }
60
61 if client.TokenID != ID {
62 t.Errorf("Expected token ID to be [%s], but was [%s]", ID, client.TokenID)
63 }
Ash Wilson6425a412014-08-29 12:30:35 -040064}