jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 1 | package testing |
Ash Wilson | 55f89b8 | 2014-10-10 14:06:30 -0400 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 9 | th "github.com/gophercloud/gophercloud/testhelper" |
| 10 | "github.com/gophercloud/gophercloud/testhelper/client" |
Ash Wilson | 55f89b8 | 2014-10-10 14:06:30 -0400 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | // ListOutput provides a single page of Tenant results. |
| 14 | const ListOutput = ` |
| 15 | { |
| 16 | "tenants": [ |
| 17 | { |
| 18 | "id": "1234", |
| 19 | "name": "Red Team", |
| 20 | "description": "The team that is red", |
| 21 | "enabled": true |
| 22 | }, |
| 23 | { |
| 24 | "id": "9876", |
| 25 | "name": "Blue Team", |
| 26 | "description": "The team that is blue", |
| 27 | "enabled": false |
| 28 | } |
| 29 | ] |
| 30 | } |
| 31 | ` |
| 32 | |
| 33 | // RedTeam is a Tenant fixture. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 34 | var RedTeam = tenants.Tenant{ |
Ash Wilson | 55f89b8 | 2014-10-10 14:06:30 -0400 | [diff] [blame] | 35 | ID: "1234", |
| 36 | Name: "Red Team", |
| 37 | Description: "The team that is red", |
| 38 | Enabled: true, |
| 39 | } |
| 40 | |
| 41 | // BlueTeam is a Tenant fixture. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 42 | var BlueTeam = tenants.Tenant{ |
Ash Wilson | 55f89b8 | 2014-10-10 14:06:30 -0400 | [diff] [blame] | 43 | ID: "9876", |
| 44 | Name: "Blue Team", |
| 45 | Description: "The team that is blue", |
| 46 | Enabled: false, |
| 47 | } |
| 48 | |
| 49 | // ExpectedTenantSlice is the slice of tenants expected to be returned from ListOutput. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 50 | var ExpectedTenantSlice = []tenants.Tenant{RedTeam, BlueTeam} |
Ash Wilson | 55f89b8 | 2014-10-10 14:06:30 -0400 | [diff] [blame] | 51 | |
| 52 | // HandleListTenantsSuccessfully creates an HTTP handler at `/tenants` on the test handler mux that |
| 53 | // responds with a list of two tenants. |
| 54 | func HandleListTenantsSuccessfully(t *testing.T) { |
| 55 | th.Mux.HandleFunc("/tenants", func(w http.ResponseWriter, r *http.Request) { |
| 56 | th.TestMethod(t, r, "GET") |
| 57 | th.TestHeader(t, r, "Accept", "application/json") |
| 58 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 59 | |
| 60 | w.Header().Set("Content-Type", "application/json") |
| 61 | w.WriteHeader(http.StatusOK) |
| 62 | fmt.Fprintf(w, ListOutput) |
| 63 | }) |
| 64 | } |