blob: 3986eb0e380acbcddbada8644c019d19d236bde9 [file] [log] [blame]
Jamie Hannaford924c09d2014-11-19 12:05:38 +01001package secgroups
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
10)
11
Jamie Hannaforda493e642014-11-19 12:40:30 +010012const rootPath = "/os-security-groups"
13
Jamie Hannaford924c09d2014-11-19 12:05:38 +010014func mockListGroupsResponse(t *testing.T) {
Jamie Hannaforda493e642014-11-19 12:40:30 +010015 th.Mux.HandleFunc(rootPath, func(w http.ResponseWriter, r *http.Request) {
Jamie Hannaford924c09d2014-11-19 12:05:38 +010016 th.TestMethod(t, r, "GET")
17 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
18
19 w.Header().Add("Content-Type", "application/json")
20 w.WriteHeader(http.StatusOK)
21
22 fmt.Fprintf(w, `
23{
24 "security_groups": [
25 {
26 "description": "default",
27 "id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
28 "name": "default",
29 "rules": [],
30 "tenant_id": "openstack"
31 }
32 ]
33}
34`)
35 })
36}
Jamie Hannaforda493e642014-11-19 12:40:30 +010037
38func mockCreateGroupResponse(t *testing.T) {
39 th.Mux.HandleFunc(rootPath, func(w http.ResponseWriter, r *http.Request) {
40 th.TestMethod(t, r, "POST")
41 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
42
43 th.TestJSONRequest(t, r, `
44{
45 "security_group": {
46 "name": "test",
47 "description": "something"
48 }
49}
50 `)
51
52 w.Header().Add("Content-Type", "application/json")
53 w.WriteHeader(http.StatusOK)
54
55 fmt.Fprintf(w, `
56{
57 "security_group": {
58 "description": "something",
59 "id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
60 "name": "test",
61 "rules": [],
62 "tenant_id": "openstack"
63 }
64}
65`)
66 })
67}