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