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