ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 1 | package testing |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
| 8 | th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | fake "github.com/gophercloud/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
| 12 | func MockCreateResponse(t *testing.T) { |
| 13 | th.Mux.HandleFunc("/security-services", func(w http.ResponseWriter, r *http.Request) { |
| 14 | th.TestMethod(t, r, "POST") |
| 15 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 16 | th.TestHeader(t, r, "Content-Type", "application/json") |
| 17 | th.TestHeader(t, r, "Accept", "application/json") |
| 18 | th.TestJSONRequest(t, r, ` |
| 19 | { |
| 20 | "security_service": { |
| 21 | "description": "Creating my first Security Service", |
| 22 | "dns_ip": "10.0.0.0/24", |
| 23 | "user": "demo", |
| 24 | "password": "***", |
| 25 | "type": "kerberos", |
| 26 | "name": "SecServ1" |
| 27 | } |
| 28 | }`) |
| 29 | |
| 30 | w.Header().Add("Content-Type", "application/json") |
| 31 | w.WriteHeader(http.StatusOK) |
| 32 | |
| 33 | fmt.Fprintf(w, ` |
| 34 | { |
| 35 | "security_service": { |
| 36 | "status": "new", |
| 37 | "domain": null, |
| 38 | "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", |
| 39 | "name": "SecServ1", |
| 40 | "created_at": "2015-09-07T12:19:10.695211", |
| 41 | "updated_at": null, |
| 42 | "server": null, |
| 43 | "dns_ip": "10.0.0.0/24", |
| 44 | "user": "demo", |
| 45 | "password": "supersecret", |
| 46 | "type": "kerberos", |
| 47 | "id": "3c829734-0679-4c17-9637-801da48c0d5f", |
| 48 | "description": "Creating my first Security Service" |
| 49 | } |
| 50 | }`) |
| 51 | }) |
| 52 | } |
ehdou | 894b50d | 2017-01-07 00:38:03 +0200 | [diff] [blame] | 53 | |
| 54 | func MockDeleteResponse(t *testing.T) { |
| 55 | th.Mux.HandleFunc("/security-services/securityServiceID", func(w http.ResponseWriter, r *http.Request) { |
| 56 | th.TestMethod(t, r, "DELETE") |
| 57 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 58 | w.WriteHeader(http.StatusAccepted) |
| 59 | }) |
| 60 | } |
ehdou | b46ba5a | 2017-03-08 20:56:49 +0200 | [diff] [blame] | 61 | |
| 62 | func MockListResponse(t *testing.T) { |
| 63 | th.Mux.HandleFunc("/security-services/detail", func(w http.ResponseWriter, r *http.Request) { |
| 64 | th.TestMethod(t, r, "GET") |
| 65 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 66 | |
| 67 | w.Header().Add("Content-Type", "application/json") |
| 68 | w.WriteHeader(http.StatusOK) |
| 69 | |
| 70 | fmt.Fprintf(w, ` |
| 71 | { |
| 72 | "security_services": [ |
| 73 | { |
| 74 | "status": "new", |
| 75 | "domain": null, |
| 76 | "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", |
| 77 | "name": "SecServ1", |
| 78 | "created_at": "2015-09-07T12:19:10.000000", |
| 79 | "description": "Creating my first Security Service", |
| 80 | "updated_at": null, |
| 81 | "server": null, |
| 82 | "dns_ip": "10.0.0.0/24", |
| 83 | "user": "demo", |
| 84 | "password": "supersecret", |
| 85 | "type": "kerberos", |
| 86 | "id": "3c829734-0679-4c17-9637-801da48c0d5f" |
| 87 | }, |
| 88 | { |
| 89 | "status": "new", |
| 90 | "domain": null, |
| 91 | "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", |
| 92 | "name": "SecServ2", |
| 93 | "created_at": "2015-09-07T12:25:03.000000", |
| 94 | "description": "Creating my second Security Service", |
| 95 | "updated_at": null, |
| 96 | "server": null, |
| 97 | "dns_ip": "10.0.0.0/24", |
| 98 | "user": null, |
| 99 | "password": null, |
| 100 | "type": "ldap", |
| 101 | "id": "5a1d3a12-34a7-4087-8983-50e9ed03509a" |
| 102 | } |
| 103 | ] |
| 104 | }`) |
| 105 | }) |
| 106 | } |
| 107 | |
| 108 | func MockFilteredListResponse(t *testing.T) { |
| 109 | th.Mux.HandleFunc("/security-services/detail", func(w http.ResponseWriter, r *http.Request) { |
| 110 | th.TestMethod(t, r, "GET") |
| 111 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 112 | |
| 113 | w.Header().Add("Content-Type", "application/json") |
| 114 | w.WriteHeader(http.StatusOK) |
| 115 | |
| 116 | fmt.Fprintf(w, ` |
| 117 | { |
| 118 | "security_services": [ |
| 119 | { |
| 120 | "status": "new", |
| 121 | "domain": null, |
| 122 | "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", |
| 123 | "name": "SecServ1", |
| 124 | "created_at": "2015-09-07T12:19:10.000000", |
| 125 | "description": "Creating my first Security Service", |
| 126 | "updated_at": null, |
| 127 | "server": null, |
| 128 | "dns_ip": "10.0.0.0/24", |
| 129 | "user": "demo", |
| 130 | "password": "supersecret", |
| 131 | "type": "kerberos", |
| 132 | "id": "3c829734-0679-4c17-9637-801da48c0d5f" |
| 133 | } |
| 134 | ] |
| 135 | }`) |
| 136 | }) |
| 137 | } |