blob: cb10313266b99210246868fa228edc83ae8ab7be [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
Joe Topjian1c236d32017-01-09 15:33:32 -070043// GetOutput provides a Get result.
44const GetOutput = `
45{
46 "project": {
47 "is_domain": false,
48 "description": "The team that is red",
49 "domain_id": "default",
50 "enabled": true,
51 "id": "1234",
52 "name": "Red Team",
53 "parent_id": null
54 }
55}
56`
57
Joe Topjianf61691c2016-11-05 12:34:59 -060058// RedTeam is a Project fixture.
59var RedTeam = projects.Project{
60 IsDomain: false,
61 Description: "The team that is red",
62 DomainID: "default",
63 Enabled: true,
64 ID: "1234",
65 Name: "Red Team",
66 ParentID: "",
67}
68
69// BlueTeam is a Project fixture.
70var BlueTeam = projects.Project{
71 IsDomain: false,
72 Description: "The team that is blue",
73 DomainID: "default",
74 Enabled: true,
75 ID: "9876",
76 Name: "Blue Team",
77 ParentID: "",
78}
79
80// ExpectedProjectSlice is the slice of projects expected to be returned from ListOutput.
81var ExpectedProjectSlice = []projects.Project{RedTeam, BlueTeam}
82
Joe Topjian1c236d32017-01-09 15:33:32 -070083// HandleListProjectsSuccessfully creates an HTTP handler at `/projects` on the
Joe Topjianf61691c2016-11-05 12:34:59 -060084// test handler mux that responds with a list of two tenants.
85func HandleListProjectsSuccessfully(t *testing.T) {
86 th.Mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
87 th.TestMethod(t, r, "GET")
88 th.TestHeader(t, r, "Accept", "application/json")
89 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
90
91 w.Header().Set("Content-Type", "application/json")
92 w.WriteHeader(http.StatusOK)
93 fmt.Fprintf(w, ListOutput)
94 })
95}
Joe Topjian1c236d32017-01-09 15:33:32 -070096
97// HandleGetProjectSuccessfully creates an HTTP handler at `/projects` on the
98// test handler mux that responds with a single project.
99func HandleGetProjectSuccessfully(t *testing.T) {
100 th.Mux.HandleFunc("/projects/1234", func(w http.ResponseWriter, r *http.Request) {
101 th.TestMethod(t, r, "GET")
102 th.TestHeader(t, r, "Accept", "application/json")
103 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
104
105 w.Header().Set("Content-Type", "application/json")
106 w.WriteHeader(http.StatusOK)
107 fmt.Fprintf(w, GetOutput)
108 })
109}