github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/vpc/v1/publicips/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk/openstack/vpc/v1/publicips" 9 "github.com/huaweicloud/golangsdk/testhelper/client" 10 11 th "github.com/huaweicloud/golangsdk/testhelper" 12 ) 13 14 var CreateOutput = ` 15 { 16 "publicip": { 17 "id": "84a71976-a8c2-42e0-8826-7fc27b876e42", 18 "status": "PENDING_CREATE", 19 "type": "5_bgp", 20 "public_ip_address": "49.4.68.149", 21 "tenant_id": "57e98940a77f4bb988a21a7d0603a626", 22 "create_time": "2018-04-20 15:59:36", 23 "bandwidth_size": 0 24 } 25 } 26 ` 27 28 var CreateResponse = publicips.PublicIPCreateResp{ 29 ID: "84a71976-a8c2-42e0-8826-7fc27b876e42", 30 Status: "PENDING_CREATE", 31 Type: "5_bgp", 32 PublicIpAddress: "49.4.68.149", 33 TenantId: "57e98940a77f4bb988a21a7d0603a626", 34 CreateTime: "2018-04-20 15:59:36", 35 BandwidthSize: 0, 36 } 37 38 func HandleCreateSuccessfully(t *testing.T) { 39 th.Mux.HandleFunc("/publicips", func(w http.ResponseWriter, r *http.Request) { 40 th.TestMethod(t, r, "POST") 41 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 42 43 w.Header().Add("Content-Type", "application/json") 44 w.WriteHeader(http.StatusOK) 45 fmt.Fprintf(w, CreateOutput) 46 }) 47 } 48 49 var UpdateOutput = ` 50 { 51 "publicip": { 52 "id": "84a71976-a8c2-42e0-8826-7fc27b876e42", 53 "status": "DOWN", 54 "type": "5_bgp", 55 "port_id": "", 56 "public_ip_address": "49.4.68.149", 57 "tenant_id": "57e98940a77f4bb988a21a7d0603a626", 58 "create_time": "2018-04-20 15:59:36", 59 "bandwidth_size": 1 60 } 61 } 62 ` 63 64 var UpdateResponse = publicips.PublicIPUpdateResp{ 65 ID: "84a71976-a8c2-42e0-8826-7fc27b876e42", 66 Status: "DOWN", 67 Type: "5_bgp", 68 PortId: "", 69 PublicIpAddress: "49.4.68.149", 70 TenantId: "57e98940a77f4bb988a21a7d0603a626", 71 CreateTime: "2018-04-20 15:59:36", 72 BandwidthSize: 1, 73 } 74 75 func HandleUpdateSuccessfully(t *testing.T) { 76 th.Mux.HandleFunc("/publicips/84a71976-a8c2-42e0-8826-7fc27b876e42", func(w http.ResponseWriter, r *http.Request) { 77 th.TestMethod(t, r, "PUT") 78 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 79 80 w.Header().Add("Content-Type", "application/json") 81 w.WriteHeader(http.StatusOK) 82 fmt.Fprintf(w, UpdateOutput) 83 }) 84 } 85 86 var GetOutput = ` 87 { 88 "publicip": { 89 "id": "84a71976-a8c2-42e0-8826-7fc27b876e42", 90 "status": "DOWN", 91 "type": "5_bgp", 92 "public_ip_address": "49.4.68.149", 93 "tenant_id": "57e98940a77f4bb988a21a7d0603a626", 94 "create_time": "2018-04-20 15:59:36", 95 "bandwidth_id": "ffdaac30-cd95-4955-a672-7b798285b68d", 96 "bandwidth_name": "bandwidth-d62f", 97 "bandwidth_share_type": "WHOLE", 98 "bandwidth_size": 1 99 } 100 } 101 ` 102 103 var GetResponse = publicips.PublicIP{ 104 ID: "84a71976-a8c2-42e0-8826-7fc27b876e42", 105 Status: "DOWN", 106 Type: "5_bgp", 107 PublicIpAddress: "49.4.68.149", 108 TenantId: "57e98940a77f4bb988a21a7d0603a626", 109 CreateTime: "2018-04-20 15:59:36", 110 BandwidthId: "ffdaac30-cd95-4955-a672-7b798285b68d", 111 BandwidthName: "bandwidth-d62f", 112 BandwidthShareType: "WHOLE", 113 BandwidthSize: 1, 114 } 115 116 func HandleGetSuccessfully(t *testing.T) { 117 th.Mux.HandleFunc("/publicips/84a71976-a8c2-42e0-8826-7fc27b876e42", func(w http.ResponseWriter, r *http.Request) { 118 th.TestMethod(t, r, "GET") 119 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 120 121 w.Header().Add("Content-Type", "application/json") 122 fmt.Fprintf(w, GetOutput) 123 }) 124 } 125 126 var ListOutput = ` 127 { 128 "publicips": [{ 129 "id": "2412e868-f93a-4dfc-b171-5096baa27403", 130 "status": "DOWN", 131 "profile": { 132 "user_id": null, 133 "product_id": null, 134 "region_id": null 135 }, 136 "profile": { 137 "user_id": "57e98940a77f4bb988a21a7d0603a626", 138 "product_id": "da27d47d84ff4adba7de3ca3b0c9ce08", 139 "region_id": "cn-north-1", 140 "order_id": "CS1803212335SQ1UD" 141 }, 142 "type": "5_sbgp", 143 "public_ip_address": "114.115.219.38", 144 "tenant_id": "57e98940a77f4bb988a21a7d0603a626", 145 "create_time": "2018-04-20 16:32:16", 146 "bandwidth_id": "916409b9-8ec8-41ce-b9d0-26002c4662ff", 147 "bandwidth_name": "bandwidth-7eaa", 148 "bandwidth_share_type": "WHOLE", 149 "bandwidth_size": 1 150 }, { 151 "id": "3faa05bd-d878-44e2-a363-f6672a9761d3", 152 "status": "DOWN", 153 "profile": { 154 "user_id": "57e98940a77f4bb988a21a7d0603a626", 155 "product_id": "da27d47d84ff4adba7de3ca3b0c9ce08", 156 "region_id": "cn-north-1", 157 "order_id": "CS1803212335SQ1UD" 158 }, 159 "profile": { 160 "user_id": "57e98940a77f4bb988a21a7d0603a626", 161 "product_id": "da27d47d84ff4adba7de3ca3b0c9ce08", 162 "region_id": "cn-north-1", 163 "order_id": "CS1803212335SQ1UD" 164 }, 165 "type": "5_bgp", 166 "public_ip_address": "49.4.22.32", 167 "tenant_id": "57e98940a77f4bb988a21a7d0603a626", 168 "create_time": "2018-03-21 15:36:34", 169 "bandwidth_id": "3c43e46e-4af1-45b8-a84d-ee6d04488d2a", 170 "bandwidth_name": "bandwidth-6f78", 171 "bandwidth_share_type": "PER", 172 "bandwidth_size": 1 173 }] 174 } 175 ` 176 177 var ListResponse = []publicips.PublicIP{ 178 { 179 ID: "2412e868-f93a-4dfc-b171-5096baa27403", 180 Status: "DOWN", 181 Type: "5_sbgp", 182 PublicIpAddress: "114.115.219.38", 183 TenantId: "57e98940a77f4bb988a21a7d0603a626", 184 CreateTime: "2018-04-20 16:32:16", 185 BandwidthId: "916409b9-8ec8-41ce-b9d0-26002c4662ff", 186 BandwidthName: "bandwidth-7eaa", 187 BandwidthShareType: "WHOLE", 188 BandwidthSize: 1, 189 Profile: publicips.Profile{ 190 UserID: "57e98940a77f4bb988a21a7d0603a626", 191 ProductID: "da27d47d84ff4adba7de3ca3b0c9ce08", 192 RegionID: "cn-north-1", 193 OrderID: "CS1803212335SQ1UD", 194 }, 195 }, 196 { 197 ID: "3faa05bd-d878-44e2-a363-f6672a9761d3", 198 Status: "DOWN", 199 Type: "5_bgp", 200 PublicIpAddress: "49.4.22.32", 201 TenantId: "57e98940a77f4bb988a21a7d0603a626", 202 CreateTime: "2018-03-21 15:36:34", 203 BandwidthId: "3c43e46e-4af1-45b8-a84d-ee6d04488d2a", 204 BandwidthName: "bandwidth-6f78", 205 BandwidthShareType: "PER", 206 BandwidthSize: 1, 207 Profile: publicips.Profile{ 208 UserID: "57e98940a77f4bb988a21a7d0603a626", 209 ProductID: "da27d47d84ff4adba7de3ca3b0c9ce08", 210 RegionID: "cn-north-1", 211 OrderID: "CS1803212335SQ1UD", 212 }, 213 }, 214 } 215 216 func HandleListSuccessfully(t *testing.T) { 217 th.Mux.HandleFunc("/publicips", func(w http.ResponseWriter, r *http.Request) { 218 th.TestMethod(t, r, "GET") 219 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 220 221 w.Header().Add("Content-Type", "application/json") 222 223 err := r.ParseForm() 224 if err != nil { 225 t.Fatalf("parse form failed: [%s]", r.Form) 226 } 227 marker := r.Form.Get("marker") 228 switch marker { 229 case "": 230 fmt.Fprintf(w, ListOutput) 231 case "3faa05bd-d878-44e2-a363-f6672a9761d3": 232 fmt.Fprintf(w, `{"publicips": []}`) 233 default: 234 t.Fatalf("Unexpected marker: [%s]", marker) 235 } 236 }) 237 } 238 239 func HandleDeleteSuccessfully(t *testing.T) { 240 th.Mux.HandleFunc("/publicips/2412e868-f93a-4dfc-b171-5096baa27403 HTTP/1.1", func(w http.ResponseWriter, r *http.Request) { 241 th.TestMethod(t, r, "DELETE") 242 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 243 244 w.Header().Add("Content-Type", "application/json") 245 fmt.Fprintf(w, "") 246 }) 247 }