github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/virtualappliances_server.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package fake 10 11 import ( 12 "context" 13 "errors" 14 "fmt" 15 azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" 19 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6" 20 "net/http" 21 "net/url" 22 "reflect" 23 "regexp" 24 ) 25 26 // VirtualAppliancesServer is a fake server for instances of the armnetwork.VirtualAppliancesClient type. 27 type VirtualAppliancesServer struct { 28 // BeginCreateOrUpdate is the fake for method VirtualAppliancesClient.BeginCreateOrUpdate 29 // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated 30 BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, parameters armnetwork.VirtualAppliance, options *armnetwork.VirtualAppliancesClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualAppliancesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) 31 32 // BeginDelete is the fake for method VirtualAppliancesClient.BeginDelete 33 // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent 34 BeginDelete func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, options *armnetwork.VirtualAppliancesClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualAppliancesClientDeleteResponse], errResp azfake.ErrorResponder) 35 36 // Get is the fake for method VirtualAppliancesClient.Get 37 // HTTP status codes to indicate success: http.StatusOK 38 Get func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, options *armnetwork.VirtualAppliancesClientGetOptions) (resp azfake.Responder[armnetwork.VirtualAppliancesClientGetResponse], errResp azfake.ErrorResponder) 39 40 // NewListPager is the fake for method VirtualAppliancesClient.NewListPager 41 // HTTP status codes to indicate success: http.StatusOK 42 NewListPager func(options *armnetwork.VirtualAppliancesClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualAppliancesClientListResponse]) 43 44 // NewListByResourceGroupPager is the fake for method VirtualAppliancesClient.NewListByResourceGroupPager 45 // HTTP status codes to indicate success: http.StatusOK 46 NewListByResourceGroupPager func(resourceGroupName string, options *armnetwork.VirtualAppliancesClientListByResourceGroupOptions) (resp azfake.PagerResponder[armnetwork.VirtualAppliancesClientListByResourceGroupResponse]) 47 48 // BeginRestart is the fake for method VirtualAppliancesClient.BeginRestart 49 // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted 50 BeginRestart func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, options *armnetwork.VirtualAppliancesClientBeginRestartOptions) (resp azfake.PollerResponder[armnetwork.VirtualAppliancesClientRestartResponse], errResp azfake.ErrorResponder) 51 52 // UpdateTags is the fake for method VirtualAppliancesClient.UpdateTags 53 // HTTP status codes to indicate success: http.StatusOK 54 UpdateTags func(ctx context.Context, resourceGroupName string, networkVirtualApplianceName string, parameters armnetwork.TagsObject, options *armnetwork.VirtualAppliancesClientUpdateTagsOptions) (resp azfake.Responder[armnetwork.VirtualAppliancesClientUpdateTagsResponse], errResp azfake.ErrorResponder) 55 } 56 57 // NewVirtualAppliancesServerTransport creates a new instance of VirtualAppliancesServerTransport with the provided implementation. 58 // The returned VirtualAppliancesServerTransport instance is connected to an instance of armnetwork.VirtualAppliancesClient via the 59 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 60 func NewVirtualAppliancesServerTransport(srv *VirtualAppliancesServer) *VirtualAppliancesServerTransport { 61 return &VirtualAppliancesServerTransport{ 62 srv: srv, 63 beginCreateOrUpdate: newTracker[azfake.PollerResponder[armnetwork.VirtualAppliancesClientCreateOrUpdateResponse]](), 64 beginDelete: newTracker[azfake.PollerResponder[armnetwork.VirtualAppliancesClientDeleteResponse]](), 65 newListPager: newTracker[azfake.PagerResponder[armnetwork.VirtualAppliancesClientListResponse]](), 66 newListByResourceGroupPager: newTracker[azfake.PagerResponder[armnetwork.VirtualAppliancesClientListByResourceGroupResponse]](), 67 beginRestart: newTracker[azfake.PollerResponder[armnetwork.VirtualAppliancesClientRestartResponse]](), 68 } 69 } 70 71 // VirtualAppliancesServerTransport connects instances of armnetwork.VirtualAppliancesClient to instances of VirtualAppliancesServer. 72 // Don't use this type directly, use NewVirtualAppliancesServerTransport instead. 73 type VirtualAppliancesServerTransport struct { 74 srv *VirtualAppliancesServer 75 beginCreateOrUpdate *tracker[azfake.PollerResponder[armnetwork.VirtualAppliancesClientCreateOrUpdateResponse]] 76 beginDelete *tracker[azfake.PollerResponder[armnetwork.VirtualAppliancesClientDeleteResponse]] 77 newListPager *tracker[azfake.PagerResponder[armnetwork.VirtualAppliancesClientListResponse]] 78 newListByResourceGroupPager *tracker[azfake.PagerResponder[armnetwork.VirtualAppliancesClientListByResourceGroupResponse]] 79 beginRestart *tracker[azfake.PollerResponder[armnetwork.VirtualAppliancesClientRestartResponse]] 80 } 81 82 // Do implements the policy.Transporter interface for VirtualAppliancesServerTransport. 83 func (v *VirtualAppliancesServerTransport) Do(req *http.Request) (*http.Response, error) { 84 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 85 method, ok := rawMethod.(string) 86 if !ok { 87 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 88 } 89 90 var resp *http.Response 91 var err error 92 93 switch method { 94 case "VirtualAppliancesClient.BeginCreateOrUpdate": 95 resp, err = v.dispatchBeginCreateOrUpdate(req) 96 case "VirtualAppliancesClient.BeginDelete": 97 resp, err = v.dispatchBeginDelete(req) 98 case "VirtualAppliancesClient.Get": 99 resp, err = v.dispatchGet(req) 100 case "VirtualAppliancesClient.NewListPager": 101 resp, err = v.dispatchNewListPager(req) 102 case "VirtualAppliancesClient.NewListByResourceGroupPager": 103 resp, err = v.dispatchNewListByResourceGroupPager(req) 104 case "VirtualAppliancesClient.BeginRestart": 105 resp, err = v.dispatchBeginRestart(req) 106 case "VirtualAppliancesClient.UpdateTags": 107 resp, err = v.dispatchUpdateTags(req) 108 default: 109 err = fmt.Errorf("unhandled API %s", method) 110 } 111 112 if err != nil { 113 return nil, err 114 } 115 116 return resp, nil 117 } 118 119 func (v *VirtualAppliancesServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { 120 if v.srv.BeginCreateOrUpdate == nil { 121 return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} 122 } 123 beginCreateOrUpdate := v.beginCreateOrUpdate.get(req) 124 if beginCreateOrUpdate == nil { 125 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkVirtualAppliances/(?P<networkVirtualApplianceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 126 regex := regexp.MustCompile(regexStr) 127 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 128 if matches == nil || len(matches) < 3 { 129 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 130 } 131 body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualAppliance](req) 132 if err != nil { 133 return nil, err 134 } 135 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 136 if err != nil { 137 return nil, err 138 } 139 networkVirtualApplianceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) 140 if err != nil { 141 return nil, err 142 } 143 respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, networkVirtualApplianceNameParam, body, nil) 144 if respErr := server.GetError(errRespr, req); respErr != nil { 145 return nil, respErr 146 } 147 beginCreateOrUpdate = &respr 148 v.beginCreateOrUpdate.add(req, beginCreateOrUpdate) 149 } 150 151 resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) 152 if err != nil { 153 return nil, err 154 } 155 156 if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { 157 v.beginCreateOrUpdate.remove(req) 158 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} 159 } 160 if !server.PollerResponderMore(beginCreateOrUpdate) { 161 v.beginCreateOrUpdate.remove(req) 162 } 163 164 return resp, nil 165 } 166 167 func (v *VirtualAppliancesServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { 168 if v.srv.BeginDelete == nil { 169 return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} 170 } 171 beginDelete := v.beginDelete.get(req) 172 if beginDelete == nil { 173 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkVirtualAppliances/(?P<networkVirtualApplianceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 174 regex := regexp.MustCompile(regexStr) 175 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 176 if matches == nil || len(matches) < 3 { 177 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 178 } 179 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 180 if err != nil { 181 return nil, err 182 } 183 networkVirtualApplianceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) 184 if err != nil { 185 return nil, err 186 } 187 respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameParam, networkVirtualApplianceNameParam, nil) 188 if respErr := server.GetError(errRespr, req); respErr != nil { 189 return nil, respErr 190 } 191 beginDelete = &respr 192 v.beginDelete.add(req, beginDelete) 193 } 194 195 resp, err := server.PollerResponderNext(beginDelete, req) 196 if err != nil { 197 return nil, err 198 } 199 200 if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { 201 v.beginDelete.remove(req) 202 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} 203 } 204 if !server.PollerResponderMore(beginDelete) { 205 v.beginDelete.remove(req) 206 } 207 208 return resp, nil 209 } 210 211 func (v *VirtualAppliancesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { 212 if v.srv.Get == nil { 213 return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} 214 } 215 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkVirtualAppliances/(?P<networkVirtualApplianceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 216 regex := regexp.MustCompile(regexStr) 217 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 218 if matches == nil || len(matches) < 3 { 219 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 220 } 221 qp := req.URL.Query() 222 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 223 if err != nil { 224 return nil, err 225 } 226 networkVirtualApplianceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) 227 if err != nil { 228 return nil, err 229 } 230 expandUnescaped, err := url.QueryUnescape(qp.Get("$expand")) 231 if err != nil { 232 return nil, err 233 } 234 expandParam := getOptional(expandUnescaped) 235 var options *armnetwork.VirtualAppliancesClientGetOptions 236 if expandParam != nil { 237 options = &armnetwork.VirtualAppliancesClientGetOptions{ 238 Expand: expandParam, 239 } 240 } 241 respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameParam, networkVirtualApplianceNameParam, options) 242 if respErr := server.GetError(errRespr, req); respErr != nil { 243 return nil, respErr 244 } 245 respContent := server.GetResponseContent(respr) 246 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 247 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 248 } 249 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).VirtualAppliance, req) 250 if err != nil { 251 return nil, err 252 } 253 return resp, nil 254 } 255 256 func (v *VirtualAppliancesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { 257 if v.srv.NewListPager == nil { 258 return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} 259 } 260 newListPager := v.newListPager.get(req) 261 if newListPager == nil { 262 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkVirtualAppliances` 263 regex := regexp.MustCompile(regexStr) 264 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 265 if matches == nil || len(matches) < 1 { 266 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 267 } 268 resp := v.srv.NewListPager(nil) 269 newListPager = &resp 270 v.newListPager.add(req, newListPager) 271 server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.VirtualAppliancesClientListResponse, createLink func() string) { 272 page.NextLink = to.Ptr(createLink()) 273 }) 274 } 275 resp, err := server.PagerResponderNext(newListPager, req) 276 if err != nil { 277 return nil, err 278 } 279 if !contains([]int{http.StatusOK}, resp.StatusCode) { 280 v.newListPager.remove(req) 281 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} 282 } 283 if !server.PagerResponderMore(newListPager) { 284 v.newListPager.remove(req) 285 } 286 return resp, nil 287 } 288 289 func (v *VirtualAppliancesServerTransport) dispatchNewListByResourceGroupPager(req *http.Request) (*http.Response, error) { 290 if v.srv.NewListByResourceGroupPager == nil { 291 return nil, &nonRetriableError{errors.New("fake for method NewListByResourceGroupPager not implemented")} 292 } 293 newListByResourceGroupPager := v.newListByResourceGroupPager.get(req) 294 if newListByResourceGroupPager == nil { 295 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkVirtualAppliances` 296 regex := regexp.MustCompile(regexStr) 297 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 298 if matches == nil || len(matches) < 2 { 299 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 300 } 301 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 302 if err != nil { 303 return nil, err 304 } 305 resp := v.srv.NewListByResourceGroupPager(resourceGroupNameParam, nil) 306 newListByResourceGroupPager = &resp 307 v.newListByResourceGroupPager.add(req, newListByResourceGroupPager) 308 server.PagerResponderInjectNextLinks(newListByResourceGroupPager, req, func(page *armnetwork.VirtualAppliancesClientListByResourceGroupResponse, createLink func() string) { 309 page.NextLink = to.Ptr(createLink()) 310 }) 311 } 312 resp, err := server.PagerResponderNext(newListByResourceGroupPager, req) 313 if err != nil { 314 return nil, err 315 } 316 if !contains([]int{http.StatusOK}, resp.StatusCode) { 317 v.newListByResourceGroupPager.remove(req) 318 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} 319 } 320 if !server.PagerResponderMore(newListByResourceGroupPager) { 321 v.newListByResourceGroupPager.remove(req) 322 } 323 return resp, nil 324 } 325 326 func (v *VirtualAppliancesServerTransport) dispatchBeginRestart(req *http.Request) (*http.Response, error) { 327 if v.srv.BeginRestart == nil { 328 return nil, &nonRetriableError{errors.New("fake for method BeginRestart not implemented")} 329 } 330 beginRestart := v.beginRestart.get(req) 331 if beginRestart == nil { 332 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkVirtualAppliances/(?P<networkVirtualApplianceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/restart` 333 regex := regexp.MustCompile(regexStr) 334 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 335 if matches == nil || len(matches) < 3 { 336 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 337 } 338 body, err := server.UnmarshalRequestAsJSON[armnetwork.VirtualApplianceInstanceIDs](req) 339 if err != nil { 340 return nil, err 341 } 342 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 343 if err != nil { 344 return nil, err 345 } 346 networkVirtualApplianceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) 347 if err != nil { 348 return nil, err 349 } 350 var options *armnetwork.VirtualAppliancesClientBeginRestartOptions 351 if !reflect.ValueOf(body).IsZero() { 352 options = &armnetwork.VirtualAppliancesClientBeginRestartOptions{ 353 NetworkVirtualApplianceInstanceIDs: &body, 354 } 355 } 356 respr, errRespr := v.srv.BeginRestart(req.Context(), resourceGroupNameParam, networkVirtualApplianceNameParam, options) 357 if respErr := server.GetError(errRespr, req); respErr != nil { 358 return nil, respErr 359 } 360 beginRestart = &respr 361 v.beginRestart.add(req, beginRestart) 362 } 363 364 resp, err := server.PollerResponderNext(beginRestart, req) 365 if err != nil { 366 return nil, err 367 } 368 369 if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { 370 v.beginRestart.remove(req) 371 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} 372 } 373 if !server.PollerResponderMore(beginRestart) { 374 v.beginRestart.remove(req) 375 } 376 377 return resp, nil 378 } 379 380 func (v *VirtualAppliancesServerTransport) dispatchUpdateTags(req *http.Request) (*http.Response, error) { 381 if v.srv.UpdateTags == nil { 382 return nil, &nonRetriableError{errors.New("fake for method UpdateTags not implemented")} 383 } 384 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkVirtualAppliances/(?P<networkVirtualApplianceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 385 regex := regexp.MustCompile(regexStr) 386 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 387 if matches == nil || len(matches) < 3 { 388 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 389 } 390 body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req) 391 if err != nil { 392 return nil, err 393 } 394 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 395 if err != nil { 396 return nil, err 397 } 398 networkVirtualApplianceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkVirtualApplianceName")]) 399 if err != nil { 400 return nil, err 401 } 402 respr, errRespr := v.srv.UpdateTags(req.Context(), resourceGroupNameParam, networkVirtualApplianceNameParam, body, nil) 403 if respErr := server.GetError(errRespr, req); respErr != nil { 404 return nil, respErr 405 } 406 respContent := server.GetResponseContent(respr) 407 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 408 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 409 } 410 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).VirtualAppliance, req) 411 if err != nil { 412 return nil, err 413 } 414 return resp, nil 415 }