github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/apigw/dedicated/v2/instances/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/chnsz/golangsdk/openstack/apigw/dedicated/v2/instances" 9 th "github.com/chnsz/golangsdk/testhelper" 10 "github.com/chnsz/golangsdk/testhelper/client" 11 ) 12 13 const ( 14 expectedCreateRequest = ` 15 { 16 "available_zone_ids": [ 17 "ap-southeast-2a", 18 "ap-southeast-2b" 19 ], 20 "bandwidth_size": 6, 21 "description": "Created by script", 22 "eip_id": "9361e906-340d-4603-9e67-dadecc6c95ad", 23 "enterprise_project_id": "4a52b236-2644-4c10-b31c-7d53a58f75a3", 24 "instance_name": "terraform-test", 25 "maintain_begin": "22:00:00", 26 "maintain_end": "02:00:00", 27 "security_group_id": "0f3fa672-e3f1-4e8d-b4d1-d160d408eca8", 28 "spec_id": "BASIC", 29 "subnet_id": "8149c60b-939f-4eec-a667-6d40aa1e14df", 30 "vpc_id": "faf4d1ae-350a-45b5-9d4b-5754b6720cce" 31 }` 32 expectedCreateResponse = ` 33 { 34 "instance_id": "e6a5871bfb5b47d19c5874790f639ef8" 35 }` 36 expectedGetResponse = ` 37 { 38 "available_zone_ids": "[cn-north-4a]", 39 "bandwidth_size": 5, 40 "charging_mode": 0, 41 "create_time": 1623742314452, 42 "enterprise_project_id": "4a52b236-2644-4c10-b31c-7d53a58f75", 43 "id": "3fb0bdaa8b27480c971f78734497cd17", 44 "ingress_ip": "192.168.155.102", 45 "instance_name": "terraform-test", 46 "instance_status": 6, 47 "instance_version": "fe97b022e6cf401c9e6679f35cf7b130", 48 "maintain_begin": "22:00:00", 49 "maintain_end": "02:00:00", 50 "nat_eip_address": "94.74.112.175", 51 "security_group_id": "4b23c9b9-f941-477b-92f0-3adc6eb76124", 52 "spec": "BASIC", 53 "status": "Running", 54 "subnet_id": "7fd65ff0-3ccb-4756-a98c-e2bfe91d3c69", 55 "supported_features": [ 56 "gateway_responses", 57 "ratelimit", 58 "request_body_size", 59 "backend_timeout", 60 "app_token", 61 "app_basic", 62 "app_secret", 63 "multi_auth", 64 "route", 65 "sign_basic", 66 "app_route", 67 "backend_client_certificate", 68 "ssl_ciphers", 69 "cors", 70 "app_quota", 71 "app_acl", 72 "real_ip_from_xff", 73 "set_resp_headers" 74 ], 75 "user_id": "05602623488025011f3bc015b70b16c3", 76 "vpc_id": "1c105033-5b68-4cfe-b58b-b1000e517908" 77 }` 78 expectedListResponse = ` 79 { 80 "instances": [ 81 { 82 "charging_mode": 0, 83 "create_time": 1623816488875, 84 "eip_address": null, 85 "enterprise_project_id": "4a52b236-2644-4c10-b31c-7d53a58f75a3", 86 "id": "de379eed30aa4d31a84f426ea3c7ef4e", 87 "instance_name": "tf-acc-test-0616", 88 "instance_status": 6, 89 "project_id": "0581b95a0b8010e32f81c015009f6587", 90 "spec": "BASIC", 91 "status": "Running", 92 "type": "apig" 93 } 94 ] 95 }` 96 ) 97 98 var ( 99 createOpts = &instances.CreateOpts{ 100 AvailableZoneIds: []string{"ap-southeast-2a", "ap-southeast-2b"}, 101 BandwidthSize: 6, 102 Description: "Created by script", 103 EipId: "9361e906-340d-4603-9e67-dadecc6c95ad", 104 EnterpriseProjectId: "4a52b236-2644-4c10-b31c-7d53a58f75a3", 105 Name: "terraform-test", 106 MaintainBegin: "22:00:00", 107 MaintainEnd: "02:00:00", 108 SecurityGroupId: "0f3fa672-e3f1-4e8d-b4d1-d160d408eca8", 109 Edition: "BASIC", 110 SubnetId: "8149c60b-939f-4eec-a667-6d40aa1e14df", 111 VpcId: "faf4d1ae-350a-45b5-9d4b-5754b6720cce", 112 } 113 114 expectedCreateResponseData = &instances.CreateResp{ 115 Id: "e6a5871bfb5b47d19c5874790f639ef8", 116 } 117 118 expectedListResponseData = []instances.BaseInstance{ 119 { 120 ChargeMode: 0, 121 CreateTimestamp: 1623816488875, 122 EnterpriseProjectId: "4a52b236-2644-4c10-b31c-7d53a58f75a3", 123 Id: "de379eed30aa4d31a84f426ea3c7ef4e", 124 Name: "tf-acc-test-0616", 125 StatusId: 6, 126 ProjectId: "0581b95a0b8010e32f81c015009f6587", 127 Edition: "BASIC", 128 Status: "Running", 129 Type: "apig", 130 }, 131 } 132 133 descContent = "Updated by script" 134 updateOpts = instances.UpdateOpts{ 135 Description: &descContent, 136 Name: "terraform-update", 137 MaintainBegin: "18:00:00", 138 MaintainEnd: "22:00:00", 139 } 140 141 updateEgressOpts = instances.EgressAccessOpts{ 142 BandwidthSize: "10", 143 } 144 145 updateIngressOpts = instances.IngressAccessOpts{ 146 EipId: "706673d2-e36b-4577-87bc-e6d6e71812f7", 147 } 148 149 expectedGetResponseData = &instances.Instance{ 150 AvailableZoneIds: "[cn-north-4a]", 151 BandwidthSize: 5, 152 ChargeMode: 0, 153 CreateTimestamp: 1623742314452, 154 EnterpriseProjectId: "4a52b236-2644-4c10-b31c-7d53a58f75", 155 Id: "3fb0bdaa8b27480c971f78734497cd17", 156 Ipv4VpcIngressAddress: "192.168.155.102", 157 Name: "terraform-test", 158 StatusId: 6, 159 Version: "fe97b022e6cf401c9e6679f35cf7b130", 160 MaintainBegin: "22:00:00", 161 MaintainEnd: "02:00:00", 162 Ipv4EgressAddress: "94.74.112.175", 163 SecurityGroupId: "4b23c9b9-f941-477b-92f0-3adc6eb76124", 164 Edition: "BASIC", 165 Status: "Running", 166 SubnetId: "7fd65ff0-3ccb-4756-a98c-e2bfe91d3c69", 167 SupportedFeatures: []string{ 168 "gateway_responses", 169 "ratelimit", 170 "request_body_size", 171 "backend_timeout", 172 "app_token", 173 "app_basic", 174 "app_secret", 175 "multi_auth", 176 "route", 177 "sign_basic", 178 "app_route", 179 "backend_client_certificate", 180 "ssl_ciphers", 181 "cors", 182 "app_quota", 183 "app_acl", 184 "real_ip_from_xff", 185 "set_resp_headers", 186 }, 187 VpcId: "1c105033-5b68-4cfe-b58b-b1000e517908", 188 UserId: "05602623488025011f3bc015b70b16c3", 189 } 190 ) 191 192 func handleV2InstanceCreate(t *testing.T) { 193 th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) { 194 th.TestMethod(t, r, "POST") 195 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 196 w.Header().Add("Content-Type", "application/json") 197 w.WriteHeader(http.StatusAccepted) 198 _, _ = fmt.Fprint(w, expectedCreateResponse) 199 }) 200 } 201 202 func handleV2InstanceGet(t *testing.T) { 203 th.Mux.HandleFunc("/instances/e6a5871bfb5b47d19c5874790f639ef8", func(w http.ResponseWriter, r *http.Request) { 204 th.TestMethod(t, r, "GET") 205 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 206 w.Header().Add("Content-Type", "application/json") 207 w.WriteHeader(http.StatusOK) 208 _, _ = fmt.Fprint(w, expectedGetResponse) 209 }) 210 } 211 212 func handleV2InstanceList(t *testing.T) { 213 th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) { 214 th.TestMethod(t, r, "GET") 215 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 216 w.Header().Add("Content-Type", "application/json") 217 w.WriteHeader(http.StatusOK) 218 _, _ = fmt.Fprint(w, expectedListResponse) 219 }) 220 } 221 222 func handleV2InstanceUpdate(t *testing.T) { 223 th.Mux.HandleFunc("/instances/e6a5871bfb5b47d19c5874790f639ef8", func(w http.ResponseWriter, r *http.Request) { 224 th.TestMethod(t, r, "PUT") 225 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 226 w.Header().Add("Content-Type", "application/json") 227 w.WriteHeader(http.StatusOK) 228 _, _ = fmt.Fprint(w, expectedGetResponse) 229 }) 230 } 231 232 func handleV2InstanceDelete(t *testing.T) { 233 th.Mux.HandleFunc("/instances/e6a5871bfb5b47d19c5874790f639ef8", func(w http.ResponseWriter, r *http.Request) { 234 th.TestMethod(t, r, "DELETE") 235 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 236 w.Header().Add("Content-Type", "application/json") 237 w.WriteHeader(http.StatusNoContent) 238 }) 239 } 240 241 func handleV2InstanceEgressDisable(t *testing.T) { 242 th.Mux.HandleFunc("/instances/e6a5871bfb5b47d19c5874790f639ef8/nat-eip", func(w http.ResponseWriter, r *http.Request) { 243 th.TestMethod(t, r, "DELETE") 244 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 245 w.Header().Add("Content-Type", "application/json") 246 w.WriteHeader(http.StatusNoContent) 247 _, _ = fmt.Fprint(w, expectedGetResponse) 248 }) 249 } 250 251 func handleV2InstanceIngressDisable(t *testing.T) { 252 th.Mux.HandleFunc("/instances/e6a5871bfb5b47d19c5874790f639ef8/eip", func(w http.ResponseWriter, r *http.Request) { 253 th.TestMethod(t, r, "DELETE") 254 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 255 w.Header().Add("Content-Type", "application/json") 256 w.WriteHeader(http.StatusOK) 257 }) 258 }