blob: 7ddba459b1947d072c5e4852b334f6d65df69a38 [file] [log] [blame]
jrperritt3d966162016-06-06 14:08:54 -05001package testing
Ash Wilson55f89b82014-10-10 14:06:30 -04002
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
jrperritt3d966162016-06-06 14:08:54 -05008 "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants"
Jon Perritt27249f42016-02-18 10:35:59 -06009 th "github.com/gophercloud/gophercloud/testhelper"
10 "github.com/gophercloud/gophercloud/testhelper/client"
Ash Wilson55f89b82014-10-10 14:06:30 -040011)
12
13// ListOutput provides a single page of Tenant results.
14const 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.
jrperritt3d966162016-06-06 14:08:54 -050034var RedTeam = tenants.Tenant{
Ash Wilson55f89b82014-10-10 14:06:30 -040035 ID: "1234",
36 Name: "Red Team",
37 Description: "The team that is red",
38 Enabled: true,
39}
40
41// BlueTeam is a Tenant fixture.
jrperritt3d966162016-06-06 14:08:54 -050042var BlueTeam = tenants.Tenant{
Ash Wilson55f89b82014-10-10 14:06:30 -040043 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.
jrperritt3d966162016-06-06 14:08:54 -050050var ExpectedTenantSlice = []tenants.Tenant{RedTeam, BlueTeam}
Ash Wilson55f89b82014-10-10 14:06:30 -040051
52// HandleListTenantsSuccessfully creates an HTTP handler at `/tenants` on the test handler mux that
53// responds with a list of two tenants.
54func 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}