jrperritt | 0bc5578 | 2016-07-27 13:50:14 -0500 | [diff] [blame] | 1 | package testing |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/gophercloud/gophercloud" |
| 9 | "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" |
| 10 | "github.com/gophercloud/gophercloud/testhelper" |
| 11 | ) |
| 12 | |
| 13 | // HandleCreateTokenWithTrustID verifies that providing certain AuthOptions and Scope results in an expected JSON structure. |
| 14 | func HandleCreateTokenWithTrustID(t *testing.T, options tokens.AuthOptionsBuilder, requestJSON string) { |
| 15 | testhelper.SetupHTTP() |
| 16 | defer testhelper.TeardownHTTP() |
| 17 | |
| 18 | client := gophercloud.ServiceClient{ |
| 19 | ProviderClient: &gophercloud.ProviderClient{}, |
| 20 | Endpoint: testhelper.Endpoint(), |
| 21 | } |
| 22 | |
| 23 | testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) { |
| 24 | testhelper.TestMethod(t, r, "POST") |
| 25 | testhelper.TestHeader(t, r, "Content-Type", "application/json") |
| 26 | testhelper.TestHeader(t, r, "Accept", "application/json") |
| 27 | testhelper.TestJSONRequest(t, r, requestJSON) |
| 28 | |
| 29 | w.WriteHeader(http.StatusCreated) |
| 30 | fmt.Fprintf(w, `{ |
| 31 | "token": { |
| 32 | "expires_at": "2014-10-02T13:45:00.000000Z" |
| 33 | } |
| 34 | }`) |
| 35 | }) |
| 36 | |
| 37 | _, err := tokens.Create(&client, options).Extract() |
| 38 | if err != nil { |
| 39 | t.Errorf("Create returned an error: %v", err) |
| 40 | } |
| 41 | } |