github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/vpc/v1/bandwidths/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/bandwidths" 9 "github.com/huaweicloud/golangsdk/testhelper/client" 10 11 th "github.com/huaweicloud/golangsdk/testhelper" 12 ) 13 14 var UpdateOutput = ` 15 { 16 "bandwidth": { 17 "id": "3c43e46e-4af1-45b8-a84d-ee6d04488d2a", 18 "name": "bandwidth-ABCD", 19 "size": 1, 20 "share_type": "PER", 21 "publicip_info": [{ 22 "publicip_id": "3faa05bd-d878-44e2-a363-f6672a9761d3", 23 "publicip_address": "49.4.22.32", 24 "publicip_type": "5_bgp" 25 }], 26 "tenant_id": "57e98940a77f4bb988a21a7d0603a626", 27 "bandwidth_type": "bgp", 28 "charge_mode": "bandwidth", 29 "billing_info": "CS1803212335SQ1UD:60564b0c1f484feaad26cda1acc6d4d8:cn-north-1:57e98940a77f4bb988a21a7d0603a626" 30 } 31 } 32 ` 33 34 var UpdateResponse = bandwidths.BandWidth{ 35 ID: "3c43e46e-4af1-45b8-a84d-ee6d04488d2a", 36 Name: "bandwidth-ABCD", 37 Size: 1, 38 ShareType: "PER", 39 PublicipInfo: []bandwidths.PublicIpinfo{ 40 { 41 PublicipId: "3faa05bd-d878-44e2-a363-f6672a9761d3", 42 PublicipAddress: "49.4.22.32", 43 PublicipType: "5_bgp", 44 }, 45 }, 46 TenantId: "57e98940a77f4bb988a21a7d0603a626", 47 BandwidthType: "bgp", 48 ChargeMode: "bandwidth", 49 BillingInfo: "CS1803212335SQ1UD:60564b0c1f484feaad26cda1acc6d4d8:cn-north-1:57e98940a77f4bb988a21a7d0603a626", 50 } 51 52 func HandleUpdateSuccessfully(t *testing.T) { 53 th.Mux.HandleFunc("/bandwidths/3c43e46e-4af1-45b8-a84d-ee6d04488d2a", func(w http.ResponseWriter, r *http.Request) { 54 th.TestMethod(t, r, "PUT") 55 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 56 57 w.Header().Add("Content-Type", "application/json") 58 w.WriteHeader(http.StatusOK) 59 fmt.Fprintf(w, UpdateOutput) 60 }) 61 } 62 63 var GetOutput = ` 64 { 65 "bandwidth": { 66 "id": "3c43e46e-4af1-45b8-a84d-ee6d04488d2a", 67 "name": "bandwidth-6f78", 68 "size": 1, 69 "share_type": "PER", 70 "publicip_info": [{ 71 "publicip_id": "3faa05bd-d878-44e2-a363-f6672a9761d3", 72 "publicip_address": "49.4.22.32", 73 "publicip_type": "5_bgp" 74 }], 75 "tenant_id": "57e98940a77f4bb988a21a7d0603a626", 76 "bandwidth_type": "bgp", 77 "charge_mode": "bandwidth", 78 "billing_info": "CS1803212335SQ1UD:60564b0c1f484feaad26cda1acc6d4d8:cn-north-1:57e98940a77f4bb988a21a7d0603a626" 79 } 80 } 81 ` 82 83 var GetResponse = bandwidths.BandWidth{ 84 ID: "3c43e46e-4af1-45b8-a84d-ee6d04488d2a", 85 Name: "bandwidth-6f78", 86 Size: 1, 87 ShareType: "PER", 88 PublicipInfo: []bandwidths.PublicIpinfo{ 89 { 90 PublicipId: "3faa05bd-d878-44e2-a363-f6672a9761d3", 91 PublicipAddress: "49.4.22.32", 92 PublicipType: "5_bgp", 93 }, 94 }, 95 TenantId: "57e98940a77f4bb988a21a7d0603a626", 96 BandwidthType: "bgp", 97 ChargeMode: "bandwidth", 98 BillingInfo: "CS1803212335SQ1UD:60564b0c1f484feaad26cda1acc6d4d8:cn-north-1:57e98940a77f4bb988a21a7d0603a626", 99 } 100 101 func HandleGetSuccessfully(t *testing.T) { 102 th.Mux.HandleFunc("/bandwidths/3c43e46e-4af1-45b8-a84d-ee6d04488d2a", func(w http.ResponseWriter, r *http.Request) { 103 th.TestMethod(t, r, "GET") 104 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 105 106 w.Header().Add("Content-Type", "application/json") 107 fmt.Fprintf(w, GetOutput) 108 }) 109 } 110 111 var ListOutput = ` 112 { 113 "bandwidths": [{ 114 "id": "3c43e46e-4af1-45b8-a84d-ee6d04488d2a", 115 "name": "bandwidth-6f78", 116 "size": 1, 117 "share_type": "PER", 118 "publicip_info": [{ 119 "publicip_id": "3faa05bd-d878-44e2-a363-f6672a9761d3", 120 "publicip_address": "49.4.22.32", 121 "publicip_type": "5_bgp" 122 }], 123 "tenant_id": "57e98940a77f4bb988a21a7d0603a626", 124 "bandwidth_type": "bgp", 125 "charge_mode": "bandwidth", 126 "billing_info": "CS1803212335SQ1UD:60564b0c1f484feaad26cda1acc6d4d8:cn-north-1:57e98940a77f4bb988a21a7d0603a626" 127 }, { 128 "id": "99cb8fb5-6f23-47c3-84a6-6ac4b7729c73", 129 "name": "bandwidth-b540", 130 "size": 1, 131 "share_type": "PER", 132 "publicip_info": [{ 133 "publicip_id": "4d60bba4-0791-4e82-8262-9bdffaeb1d14", 134 "publicip_address": "49.4.4.36", 135 "publicip_type": "5_bgp" 136 }], 137 "tenant_id": "57e98940a77f4bb988a21a7d0603a626", 138 "bandwidth_type": "bgp", 139 "charge_mode": "bandwidth", 140 "billing_info": "CS1803212337UFH9F:60564b0c1f484feaad26cda1acc6d4d8:cn-north-1:57e98940a77f4bb988a21a7d0603a626" 141 }] 142 } 143 ` 144 145 var ListResponse = []bandwidths.BandWidth{ 146 { 147 ID: "3c43e46e-4af1-45b8-a84d-ee6d04488d2a", 148 Name: "bandwidth-6f78", 149 Size: 1, 150 ShareType: "PER", 151 PublicipInfo: []bandwidths.PublicIpinfo{ 152 { 153 PublicipId: "3faa05bd-d878-44e2-a363-f6672a9761d3", 154 PublicipAddress: "49.4.22.32", 155 PublicipType: "5_bgp", 156 }, 157 }, 158 TenantId: "57e98940a77f4bb988a21a7d0603a626", 159 BandwidthType: "bgp", 160 ChargeMode: "bandwidth", 161 BillingInfo: "CS1803212335SQ1UD:60564b0c1f484feaad26cda1acc6d4d8:cn-north-1:57e98940a77f4bb988a21a7d0603a626", 162 }, 163 { 164 ID: "99cb8fb5-6f23-47c3-84a6-6ac4b7729c73", 165 Name: "bandwidth-b540", 166 Size: 1, 167 ShareType: "PER", 168 PublicipInfo: []bandwidths.PublicIpinfo{ 169 { 170 PublicipId: "4d60bba4-0791-4e82-8262-9bdffaeb1d14", 171 PublicipAddress: "49.4.4.36", 172 PublicipType: "5_bgp", 173 }, 174 }, 175 TenantId: "57e98940a77f4bb988a21a7d0603a626", 176 BandwidthType: "bgp", 177 ChargeMode: "bandwidth", 178 BillingInfo: "CS1803212337UFH9F:60564b0c1f484feaad26cda1acc6d4d8:cn-north-1:57e98940a77f4bb988a21a7d0603a626", 179 }, 180 } 181 182 func HandleListSuccessfully(t *testing.T) { 183 th.Mux.HandleFunc("/bandwidths", func(w http.ResponseWriter, r *http.Request) { 184 th.TestMethod(t, r, "GET") 185 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 186 187 w.Header().Add("Content-Type", "application/json") 188 189 err := r.ParseForm() 190 if err != nil { 191 t.Fatalf("parse form failed: [%s]", r.Form) 192 } 193 marker := r.Form.Get("marker") 194 switch marker { 195 case "": 196 fmt.Fprintf(w, ListOutput) 197 case "99cb8fb5-6f23-47c3-84a6-6ac4b7729c73": 198 fmt.Fprintf(w, `{"bandwidths": []}`) 199 default: 200 t.Fatalf("Unexpected marker: [%s]", marker) 201 } 202 }) 203 }