github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/apigw/v2/apis/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk" 9 "github.com/huaweicloud/golangsdk/openstack/apigw/v2/apis" 10 th "github.com/huaweicloud/golangsdk/testhelper" 11 "github.com/huaweicloud/golangsdk/testhelper/client" 12 ) 13 14 const ( 15 expectedCreateResponse = ` 16 { 17 "arrange_necessary": 2, 18 "auth_opt": { 19 "app_code_auth_type": "DISABLE" 20 }, 21 "auth_type": "AUTHORIZER", 22 "authorizer_id": "8b9c7d67ca144a5da7bc9cbccedfe753", 23 "backend_api": { 24 "enable_client_ssl": false, 25 "req_method": "GET", 26 "req_protocol": "HTTP", 27 "req_uri": "/backend/users", 28 "timeout": 6000, 29 "url_domain": "69bb5628fce741a1b901b08cde7b814d", 30 "vpc_channel_info": { 31 "vpc_channel_id": "69bb5628fce741a1b901b08cde7b814d" 32 }, 33 "vpc_channel_status": 1 34 }, 35 "backend_params": [ 36 { 37 "location": "HEADER", 38 "name": "X-User-Name", 39 "origin": "SYSTEM", 40 "value": "$context.authorizer.frontend.user_name" 41 } 42 ], 43 "backend_type": "HTTP", 44 "cors": false, 45 "group_id": "c6e46c49a6734c918262a16c3c1a3a13", 46 "group_name": "terraform_test", 47 "group_version": "V1", 48 "id": "cded6d80fc9f442c9842eaf854f10525", 49 "match_mode": "NORMAL", 50 "name": "terraform_test", 51 "register_time": "2021-08-05T03:33:35.360020923Z", 52 "req_method": "POST", 53 "req_protocol": "HTTP", 54 "req_uri": "/terraform/users", 55 "status": 1, 56 "type": 2, 57 "update_time": "2021-08-05T03:33:35.360021226Z" 58 }` 59 60 expectedGetResponse = ` 61 { 62 "arrange_necessary": 2, 63 "auth_opt": { 64 "app_code_auth_type": "DISABLE" 65 }, 66 "auth_type": "AUTHORIZER", 67 "authorizer_id": "8b9c7d67ca144a5da7bc9cbccedfe753", 68 "backend_api": { 69 "enable_client_ssl": false, 70 "req_method": "GET", 71 "req_protocol": "HTTP", 72 "req_uri": "/backend/users", 73 "timeout": 6000, 74 "url_domain": "69bb5628fce741a1b901b08cde7b814d", 75 "vpc_channel_info": { 76 "vpc_channel_id": "69bb5628fce741a1b901b08cde7b814d" 77 }, 78 "vpc_channel_status": 1 79 }, 80 "backend_params": [ 81 { 82 "location": "HEADER", 83 "name": "X-User-Name", 84 "origin": "SYSTEM", 85 "value": "$context.authorizer.frontend.user_name" 86 } 87 ], 88 "backend_type": "HTTP", 89 "cors": false, 90 "group_id": "c6e46c49a6734c918262a16c3c1a3a13", 91 "group_name": "terraform_test", 92 "group_version": "V1", 93 "id": "cded6d80fc9f442c9842eaf854f10525", 94 "match_mode": "NORMAL", 95 "name": "terraform_test", 96 "register_time": "2021-08-05T03:33:35.360020923Z", 97 "req_method": "POST", 98 "req_protocol": "HTTP", 99 "req_uri": "/terraform/users", 100 "status": 1, 101 "type": 2, 102 "update_time": "2021-08-05T03:33:35Z" 103 } 104 ` 105 106 expectedListResponse = ` 107 { 108 "total": 1, 109 "size": 1, 110 "apis": [ 111 { 112 "arrange_necessary": 2, 113 "auth_opt": { 114 "app_code_auth_type": "DISABLE" 115 }, 116 "auth_type": "AUTHORIZER", 117 "authorizer_id": "8b9c7d67ca144a5da7bc9cbccedfe753", 118 "backend_api": { 119 "enable_client_ssl": false, 120 "req_method": "GET", 121 "req_protocol": "HTTP", 122 "req_uri": "/backend/users", 123 "timeout": 6000, 124 "url_domain": "69bb5628fce741a1b901b08cde7b814d", 125 "vpc_channel_info": { 126 "vpc_channel_id": "69bb5628fce741a1b901b08cde7b814d" 127 }, 128 "vpc_channel_status": 1 129 }, 130 "backend_params": [ 131 { 132 "location": "HEADER", 133 "name": "X-User-Name", 134 "origin": "SYSTEM", 135 "value": "$context.authorizer.frontend.user_name" 136 } 137 ], 138 "backend_type": "HTTP", 139 "cors": false, 140 "group_id": "c6e46c49a6734c918262a16c3c1a3a13", 141 "group_name": "terraform_test", 142 "group_version": "V1", 143 "id": "cded6d80fc9f442c9842eaf854f10525", 144 "match_mode": "NORMAL", 145 "name": "terraform_test", 146 "register_time": "2021-08-05T03:33:35.360020923Z", 147 "req_method": "POST", 148 "req_protocol": "HTTP", 149 "req_uri": "/terraform/users", 150 "status": 1, 151 "type": 2, 152 "update_time": "2021-08-05T03:33:35Z" 153 } 154 ] 155 }` 156 ) 157 158 var ( 159 createOpts = apis.APIOpts{ 160 GroupId: "c6e46c49a6734c918262a16c3c1a3a13", 161 Type: 2, 162 AuthType: "AUTHORIZER", 163 AuthorizerId: "8b9c7d67ca144a5da7bc9cbccedfe753", 164 Cors: golangsdk.Disabled, 165 MatchMode: "NORMAL", 166 Name: "terraform_test", 167 ReqURI: "/terraform/users", 168 ReqMethod: "POST", 169 ReqProtocol: "HTTP", 170 BackendType: "HTTP", 171 WebInfo: &apis.Web{ 172 ClientSslEnable: golangsdk.Disabled, 173 ReqMethod: "POST", 174 ReqProtocol: "HTTP", 175 ReqURI: "/backend/users", 176 Timeout: 6000, 177 VpcChannelInfo: &apis.VpcChannel{ 178 VpcChannelId: "69bb5628fce741a1b901b08cde7b814d", 179 }, 180 VpcChannelStatus: 1, 181 }, 182 BackendParams: []apis.BackendParamBase{ 183 { 184 Location: "HEADER", 185 Name: "X-User-Name", 186 Origin: "SYSTEM", 187 Value: "$context.authorizer.frontend.user_name", 188 }, 189 }, 190 } 191 192 expectedCreateResponseData = &apis.APIResp{ 193 ArrangeNecessary: 2, 194 AuthType: "AUTHORIZER", 195 AuthorizerId: "8b9c7d67ca144a5da7bc9cbccedfe753", 196 AuthOpt: apis.AuthOpt{ 197 AppCodeAuthType: "DISABLE", 198 }, 199 WebInfo: apis.Web{ 200 ClientSslEnable: golangsdk.Disabled, 201 ReqMethod: "GET", 202 ReqProtocol: "HTTP", 203 ReqURI: "/backend/users", 204 Timeout: 6000, 205 DomainURL: "69bb5628fce741a1b901b08cde7b814d", 206 VpcChannelInfo: &apis.VpcChannel{ 207 VpcChannelId: "69bb5628fce741a1b901b08cde7b814d", 208 }, 209 VpcChannelStatus: 1, 210 }, 211 BackendParams: []apis.BackendParamResp{ 212 { 213 Location: "HEADER", 214 Name: "X-User-Name", 215 Origin: "SYSTEM", 216 Value: "$context.authorizer.frontend.user_name", 217 }, 218 }, 219 BackendType: "HTTP", 220 Cors: false, 221 GroupId: "c6e46c49a6734c918262a16c3c1a3a13", 222 GroupName: "terraform_test", 223 GroupVersion: "V1", 224 ID: "cded6d80fc9f442c9842eaf854f10525", 225 MatchMode: "NORMAL", 226 Name: "terraform_test", 227 RegisterTime: "2021-08-05T03:33:35.360020923Z", 228 ReqMethod: "POST", 229 ReqProtocol: "HTTP", 230 ReqURI: "/terraform/users", 231 Status: 1, 232 Type: 2, 233 UpdateTime: "2021-08-05T03:33:35.360021226Z", 234 } 235 236 expectedGetResponseData = &apis.APIResp{ 237 ArrangeNecessary: 2, 238 AuthType: "AUTHORIZER", 239 AuthorizerId: "8b9c7d67ca144a5da7bc9cbccedfe753", 240 AuthOpt: apis.AuthOpt{ 241 AppCodeAuthType: "DISABLE", 242 }, 243 WebInfo: apis.Web{ 244 ClientSslEnable: golangsdk.Disabled, 245 ReqMethod: "GET", 246 ReqProtocol: "HTTP", 247 ReqURI: "/backend/users", 248 Timeout: 6000, 249 DomainURL: "69bb5628fce741a1b901b08cde7b814d", 250 VpcChannelInfo: &apis.VpcChannel{ 251 VpcChannelId: "69bb5628fce741a1b901b08cde7b814d", 252 }, 253 VpcChannelStatus: 1, 254 }, 255 BackendParams: []apis.BackendParamResp{ 256 { 257 Location: "HEADER", 258 Name: "X-User-Name", 259 Origin: "SYSTEM", 260 Value: "$context.authorizer.frontend.user_name", 261 }, 262 }, 263 BackendType: "HTTP", 264 Cors: false, 265 GroupId: "c6e46c49a6734c918262a16c3c1a3a13", 266 GroupName: "terraform_test", 267 GroupVersion: "V1", 268 ID: "cded6d80fc9f442c9842eaf854f10525", 269 MatchMode: "NORMAL", 270 Name: "terraform_test", 271 RegisterTime: "2021-08-05T03:33:35.360020923Z", 272 ReqMethod: "POST", 273 ReqProtocol: "HTTP", 274 ReqURI: "/terraform/users", 275 Status: 1, 276 Type: 2, 277 UpdateTime: "2021-08-05T03:33:35Z", 278 } 279 280 listOpts = &apis.ListOpts{ 281 Name: "terraform_test", 282 } 283 284 expectedListResponseData = []apis.APIResp{ 285 { 286 ArrangeNecessary: 2, 287 AuthType: "AUTHORIZER", 288 AuthorizerId: "8b9c7d67ca144a5da7bc9cbccedfe753", 289 AuthOpt: apis.AuthOpt{ 290 AppCodeAuthType: "DISABLE", 291 }, 292 WebInfo: apis.Web{ 293 ClientSslEnable: golangsdk.Disabled, 294 ReqMethod: "GET", 295 ReqProtocol: "HTTP", 296 ReqURI: "/backend/users", 297 Timeout: 6000, 298 DomainURL: "69bb5628fce741a1b901b08cde7b814d", 299 VpcChannelInfo: &apis.VpcChannel{ 300 VpcChannelId: "69bb5628fce741a1b901b08cde7b814d", 301 }, 302 VpcChannelStatus: 1, 303 }, 304 BackendParams: []apis.BackendParamResp{ 305 { 306 Location: "HEADER", 307 Name: "X-User-Name", 308 Origin: "SYSTEM", 309 Value: "$context.authorizer.frontend.user_name", 310 }, 311 }, 312 BackendType: "HTTP", 313 Cors: false, 314 GroupId: "c6e46c49a6734c918262a16c3c1a3a13", 315 GroupName: "terraform_test", 316 GroupVersion: "V1", 317 ID: "cded6d80fc9f442c9842eaf854f10525", 318 MatchMode: "NORMAL", 319 Name: "terraform_test", 320 RegisterTime: "2021-08-05T03:33:35.360020923Z", 321 ReqMethod: "POST", 322 ReqProtocol: "HTTP", 323 ReqURI: "/terraform/users", 324 Status: 1, 325 Type: 2, 326 UpdateTime: "2021-08-05T03:33:35Z", 327 }, 328 } 329 ) 330 331 func handleV2APICreate(t *testing.T) { 332 th.Mux.HandleFunc("/instances/33fc92ffb7e749df952ecc7729d972bc/apis", 333 func(w http.ResponseWriter, r *http.Request) { 334 th.TestMethod(t, r, "POST") 335 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 336 w.Header().Add("Content-Type", "application/json") 337 w.WriteHeader(http.StatusCreated) 338 _, _ = fmt.Fprint(w, expectedCreateResponse) 339 }) 340 } 341 342 func handleV2APIGet(t *testing.T) { 343 th.Mux.HandleFunc("/instances/33fc92ffb7e749df952ecc7729d972bc/apis/cded6d80fc9f442c9842eaf854f10525", 344 func(w http.ResponseWriter, r *http.Request) { 345 th.TestMethod(t, r, "GET") 346 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 347 w.Header().Add("Content-Type", "application/json") 348 w.WriteHeader(http.StatusOK) 349 _, _ = fmt.Fprint(w, expectedGetResponse) 350 }) 351 } 352 353 func handleV2APIList(t *testing.T) { 354 th.Mux.HandleFunc("/instances/33fc92ffb7e749df952ecc7729d972bc/apis", 355 func(w http.ResponseWriter, r *http.Request) { 356 th.TestMethod(t, r, "GET") 357 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 358 w.Header().Add("Content-Type", "application/json") 359 w.WriteHeader(http.StatusOK) 360 _, _ = fmt.Fprint(w, expectedListResponse) 361 }) 362 } 363 364 func handleV2APIUpdate(t *testing.T) { 365 th.Mux.HandleFunc("/instances/33fc92ffb7e749df952ecc7729d972bc/apis/cded6d80fc9f442c9842eaf854f10525", 366 func(w http.ResponseWriter, r *http.Request) { 367 th.TestMethod(t, r, "PUT") 368 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 369 w.Header().Add("Content-Type", "application/json") 370 w.WriteHeader(http.StatusOK) 371 _, _ = fmt.Fprint(w, expectedGetResponse) 372 }) 373 } 374 375 func handleV2APIDelete(t *testing.T) { 376 th.Mux.HandleFunc("/instances/33fc92ffb7e749df952ecc7729d972bc/apis/cded6d80fc9f442c9842eaf854f10525", 377 func(w http.ResponseWriter, r *http.Request) { 378 th.TestMethod(t, r, "DELETE") 379 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 380 w.Header().Add("Content-Type", "application/json") 381 w.WriteHeader(http.StatusNoContent) 382 }) 383 }