github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dns/v2/zones/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/opentelekomcloud/gophertelekomcloud/openstack/dns/v2/zones" 9 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 10 "github.com/opentelekomcloud/gophertelekomcloud/testhelper/client" 11 ) 12 13 // ListOutput is a sample response to a List call. 14 const ListOutput = ` 15 { 16 "links": { 17 "self": "https://example.com:9001/v2/zones" 18 }, 19 "metadata": { 20 "total_count": 2 21 }, 22 "zones": [ 23 { 24 "id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", 25 "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2", 26 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 27 "name": "example.org.", 28 "email": "joe@example.org", 29 "ttl": 7200, 30 "serial": 1404757531, 31 "status": "ACTIVE", 32 "description": "This is an example zone.", 33 "masters": [], 34 "created_at": "2014-07-07T18:25:31.275934", 35 "updated_at": null, 36 "links": { 37 "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3" 38 } 39 }, 40 { 41 "id": "34c4561c-9205-4386-9df5-167436f5a222", 42 "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2", 43 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 44 "name": "foo.example.com.", 45 "email": "joe@foo.example.com", 46 "ttl": 7200, 47 "serial": 1488053571, 48 "status": "ACTIVE", 49 "description": "This is another example zone.", 50 "masters": ["example.com."], 51 "created_at": "2014-07-07T18:25:31.275934", 52 "updated_at": "2015-02-25T20:23:01.234567", 53 "links": { 54 "self": "https://127.0.0.1:9001/v2/zones/34c4561c-9205-4386-9df5-167436f5a222" 55 } 56 } 57 ] 58 } 59 ` 60 61 // GetOutput is a sample response to a Get call. 62 const GetOutput = ` 63 { 64 "id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", 65 "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2", 66 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 67 "name": "example.org.", 68 "email": "joe@example.org", 69 "ttl": 7200, 70 "serial": 1404757531, 71 "status": "ACTIVE", 72 "description": "This is an example zone.", 73 "masters": [], 74 "created_at": "2014-07-07T18:25:31.275934", 75 "updated_at": null, 76 "links": { 77 "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3" 78 } 79 } 80 ` 81 82 // FirstZone is the first result in ListOutput 83 var FirstZone = zones.Zone{ 84 ID: "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", 85 PoolID: "572ba08c-d929-4c70-8e42-03824bb24ca2", 86 ProjectID: "4335d1f0-f793-11e2-b778-0800200c9a66", 87 Name: "example.org.", 88 Email: "joe@example.org", 89 TTL: 7200, 90 Serial: 1404757531, 91 Status: "ACTIVE", 92 Description: "This is an example zone.", 93 Masters: []string{}, 94 CreatedAt: "2014-07-07T18:25:31.275934", 95 Links: map[string]interface{}{ 96 "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", 97 }, 98 } 99 100 var SecondZone = zones.Zone{ 101 ID: "34c4561c-9205-4386-9df5-167436f5a222", 102 PoolID: "572ba08c-d929-4c70-8e42-03824bb24ca2", 103 ProjectID: "4335d1f0-f793-11e2-b778-0800200c9a66", 104 Name: "foo.example.com.", 105 Email: "joe@foo.example.com", 106 TTL: 7200, 107 Serial: 1488053571, 108 Status: "ACTIVE", 109 Description: "This is another example zone.", 110 Masters: []string{"example.com."}, 111 CreatedAt: "2014-07-07T18:25:31.275934", 112 UpdatedAt: "2015-02-25T20:23:01.234567", 113 Links: map[string]interface{}{ 114 "self": "https://127.0.0.1:9001/v2/zones/34c4561c-9205-4386-9df5-167436f5a222", 115 }, 116 } 117 118 // ExpectedZonesSlice is the slice of results that should be parsed 119 // from ListOutput, in the expected order. 120 var ExpectedZonesSlice = []zones.Zone{FirstZone, SecondZone} 121 122 // HandleListSuccessfully configures the test server to respond to a List request. 123 func HandleListSuccessfully(t *testing.T) { 124 th.Mux.HandleFunc("/zones", func(w http.ResponseWriter, r *http.Request) { 125 th.TestMethod(t, r, "GET") 126 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 127 128 w.Header().Add("Content-Type", "application/json") 129 _, _ = fmt.Fprint(w, ListOutput) 130 }) 131 } 132 133 // HandleGetSuccessfully configures the test server to respond to a List request. 134 func HandleGetSuccessfully(t *testing.T) { 135 th.Mux.HandleFunc("/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", func(w http.ResponseWriter, r *http.Request) { 136 th.TestMethod(t, r, "GET") 137 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 138 139 w.Header().Add("Content-Type", "application/json") 140 _, _ = fmt.Fprint(w, GetOutput) 141 }) 142 } 143 144 // CreateZoneRequest is a sample request to create a zone. 145 const CreateZoneRequest = ` 146 { 147 "name": "example.org.", 148 "email": "joe@example.org", 149 "ttl": 7200, 150 "description": "This is an example zone." 151 } 152 ` 153 154 // CreateZoneResponse is a sample response to a create request. 155 const CreateZoneResponse = ` 156 { 157 "id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", 158 "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2", 159 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 160 "name": "example.org.", 161 "email": "joe@example.org", 162 "ttl": 7200, 163 "serial": 1404757531, 164 "status": "ACTIVE", 165 "description": "This is an example zone.", 166 "masters": [], 167 "created_at": "2014-07-07T18:25:31.275934", 168 "updated_at": null, 169 "links": { 170 "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3" 171 } 172 } 173 ` 174 175 // CreatedZone is the expected created zone 176 var CreatedZone = FirstZone 177 178 // HandleCreateSuccessfully configures the test server to respond to a Create request. 179 func HandleCreateSuccessfully(t *testing.T) { 180 th.Mux.HandleFunc("/zones", func(w http.ResponseWriter, r *http.Request) { 181 th.TestMethod(t, r, "POST") 182 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 183 th.TestJSONRequest(t, r, CreateZoneRequest) 184 185 w.WriteHeader(http.StatusCreated) 186 w.Header().Add("Content-Type", "application/json") 187 _, _ = fmt.Fprint(w, CreateZoneResponse) 188 }) 189 } 190 191 // UpdateZoneRequest is a sample request to update a zone. 192 const UpdateZoneRequest = ` 193 { 194 "ttl": 600, 195 "description": "Updated Description" 196 } 197 ` 198 199 // UpdateZoneResponse is a sample response to update a zone. 200 const UpdateZoneResponse = ` 201 { 202 "id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", 203 "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2", 204 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 205 "name": "example.org.", 206 "email": "joe@example.org", 207 "ttl": 600, 208 "serial": 1404757531, 209 "status": "PENDING", 210 "description": "Updated Description", 211 "masters": [], 212 "created_at": "2014-07-07T18:25:31.275934", 213 "updated_at": null, 214 "links": { 215 "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3" 216 } 217 } 218 ` 219 220 // HandleUpdateSuccessfully configures the test server to respond to an Update request. 221 func HandleUpdateSuccessfully(t *testing.T) { 222 th.Mux.HandleFunc("/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", 223 func(w http.ResponseWriter, r *http.Request) { 224 th.TestMethod(t, r, "PATCH") 225 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 226 th.TestJSONRequest(t, r, UpdateZoneRequest) 227 228 w.WriteHeader(http.StatusOK) 229 w.Header().Add("Content-Type", "application/json") 230 _, _ = fmt.Fprint(w, UpdateZoneResponse) 231 }) 232 } 233 234 // DeleteZoneResponse is a sample response to update a zone. 235 const DeleteZoneResponse = ` 236 { 237 "id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", 238 "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2", 239 "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", 240 "name": "example.org.", 241 "email": "joe@example.org", 242 "ttl": 600, 243 "serial": 1404757531, 244 "status": "PENDING", 245 "description": "Updated Description", 246 "masters": [], 247 "created_at": "2014-07-07T18:25:31.275934", 248 "updated_at": null, 249 "links": { 250 "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3" 251 } 252 } 253 ` 254 255 // HandleDeleteSuccessfully configures the test server to respond to an Delete request. 256 func HandleDeleteSuccessfully(t *testing.T) { 257 th.Mux.HandleFunc("/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", 258 func(w http.ResponseWriter, r *http.Request) { 259 th.TestMethod(t, r, "DELETE") 260 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 261 262 w.WriteHeader(http.StatusAccepted) 263 w.Header().Add("Content-Type", "application/json") 264 _, _ = fmt.Fprint(w, DeleteZoneResponse) 265 }) 266 }