blob: c4d9c03a2307ba0175b19cd28bf05a94926cade9 [file] [log] [blame]
Joe Topjianf61691c2016-11-05 12:34:59 -06001package testing
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 "github.com/gophercloud/gophercloud/openstack/identity/v3/projects"
9 th "github.com/gophercloud/gophercloud/testhelper"
10 "github.com/gophercloud/gophercloud/testhelper/client"
11)
12
13// ListOutput provides a single page of Project results.
14const ListOutput = `
15{
16 "projects": [
17 {
18 "is_domain": false,
19 "description": "The team that is red",
20 "domain_id": "default",
21 "enabled": true,
22 "id": "1234",
23 "name": "Red Team",
24 "parent_id": null
25 },
26 {
27 "is_domain": false,
28 "description": "The team that is blue",
29 "domain_id": "default",
30 "enabled": true,
31 "id": "9876",
32 "name": "Blue Team",
33 "parent_id": null
34 }
35 ],
36 "links": {
37 "next": null,
38 "previous": null
39 }
40}
41`
42
43// RedTeam is a Project fixture.
44var RedTeam = projects.Project{
45 IsDomain: false,
46 Description: "The team that is red",
47 DomainID: "default",
48 Enabled: true,
49 ID: "1234",
50 Name: "Red Team",
51 ParentID: "",
52}
53
54// BlueTeam is a Project fixture.
55var BlueTeam = projects.Project{
56 IsDomain: false,
57 Description: "The team that is blue",
58 DomainID: "default",
59 Enabled: true,
60 ID: "9876",
61 Name: "Blue Team",
62 ParentID: "",
63}
64
65// ExpectedProjectSlice is the slice of projects expected to be returned from ListOutput.
66var ExpectedProjectSlice = []projects.Project{RedTeam, BlueTeam}
67
68// HandleListProjectSuccessfully creates an HTTP handler at `/projects` on the
69// test handler mux that responds with a list of two tenants.
70func HandleListProjectsSuccessfully(t *testing.T) {
71 th.Mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
72 th.TestMethod(t, r, "GET")
73 th.TestHeader(t, r, "Accept", "application/json")
74 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
75
76 w.Header().Set("Content-Type", "application/json")
77 w.WriteHeader(http.StatusOK)
78 fmt.Fprintf(w, ListOutput)
79 })
80}