Ash Wilson | 6425a41 | 2014-08-29 12:30:35 -0400 | [diff] [blame] | 1 | package openstack |
| 2 | |
| 3 | import ( |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame^] | 4 | "fmt" |
| 5 | "net/http" |
Ash Wilson | 6425a41 | 2014-08-29 12:30:35 -0400 | [diff] [blame] | 6 | "testing" |
| 7 | |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame^] | 8 | "github.com/rackspace/gophercloud" |
Ash Wilson | 6425a41 | 2014-08-29 12:30:35 -0400 | [diff] [blame] | 9 | "github.com/rackspace/gophercloud/testhelper" |
| 10 | ) |
| 11 | |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame^] | 12 | func TestNewClientV3(t *testing.T) { |
Ash Wilson | 6425a41 | 2014-08-29 12:30:35 -0400 | [diff] [blame] | 13 | testhelper.SetupHTTP() |
| 14 | defer testhelper.TeardownHTTP() |
Ash Wilson | 4dee1b8 | 2014-08-29 14:56:45 -0400 | [diff] [blame^] | 15 | |
| 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 Wilson | 6425a41 | 2014-08-29 12:30:35 -0400 | [diff] [blame] | 64 | } |