github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/vpnsitesconfiguration_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/resourcemanager/network/armnetwork/v6" 19 "net/http" 20 "net/url" 21 "regexp" 22 ) 23 24 // VPNSitesConfigurationServer is a fake server for instances of the armnetwork.VPNSitesConfigurationClient type. 25 type VPNSitesConfigurationServer struct { 26 // BeginDownload is the fake for method VPNSitesConfigurationClient.BeginDownload 27 // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted 28 BeginDownload func(ctx context.Context, resourceGroupName string, virtualWANName string, request armnetwork.GetVPNSitesConfigurationRequest, options *armnetwork.VPNSitesConfigurationClientBeginDownloadOptions) (resp azfake.PollerResponder[armnetwork.VPNSitesConfigurationClientDownloadResponse], errResp azfake.ErrorResponder) 29 } 30 31 // NewVPNSitesConfigurationServerTransport creates a new instance of VPNSitesConfigurationServerTransport with the provided implementation. 32 // The returned VPNSitesConfigurationServerTransport instance is connected to an instance of armnetwork.VPNSitesConfigurationClient via the 33 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 34 func NewVPNSitesConfigurationServerTransport(srv *VPNSitesConfigurationServer) *VPNSitesConfigurationServerTransport { 35 return &VPNSitesConfigurationServerTransport{ 36 srv: srv, 37 beginDownload: newTracker[azfake.PollerResponder[armnetwork.VPNSitesConfigurationClientDownloadResponse]](), 38 } 39 } 40 41 // VPNSitesConfigurationServerTransport connects instances of armnetwork.VPNSitesConfigurationClient to instances of VPNSitesConfigurationServer. 42 // Don't use this type directly, use NewVPNSitesConfigurationServerTransport instead. 43 type VPNSitesConfigurationServerTransport struct { 44 srv *VPNSitesConfigurationServer 45 beginDownload *tracker[azfake.PollerResponder[armnetwork.VPNSitesConfigurationClientDownloadResponse]] 46 } 47 48 // Do implements the policy.Transporter interface for VPNSitesConfigurationServerTransport. 49 func (v *VPNSitesConfigurationServerTransport) Do(req *http.Request) (*http.Response, error) { 50 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 51 method, ok := rawMethod.(string) 52 if !ok { 53 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 54 } 55 56 var resp *http.Response 57 var err error 58 59 switch method { 60 case "VPNSitesConfigurationClient.BeginDownload": 61 resp, err = v.dispatchBeginDownload(req) 62 default: 63 err = fmt.Errorf("unhandled API %s", method) 64 } 65 66 if err != nil { 67 return nil, err 68 } 69 70 return resp, nil 71 } 72 73 func (v *VPNSitesConfigurationServerTransport) dispatchBeginDownload(req *http.Request) (*http.Response, error) { 74 if v.srv.BeginDownload == nil { 75 return nil, &nonRetriableError{errors.New("fake for method BeginDownload not implemented")} 76 } 77 beginDownload := v.beginDownload.get(req) 78 if beginDownload == nil { 79 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/virtualWans/(?P<virtualWANName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnConfiguration` 80 regex := regexp.MustCompile(regexStr) 81 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 82 if matches == nil || len(matches) < 3 { 83 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 84 } 85 body, err := server.UnmarshalRequestAsJSON[armnetwork.GetVPNSitesConfigurationRequest](req) 86 if err != nil { 87 return nil, err 88 } 89 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 90 if err != nil { 91 return nil, err 92 } 93 virtualWANNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("virtualWANName")]) 94 if err != nil { 95 return nil, err 96 } 97 respr, errRespr := v.srv.BeginDownload(req.Context(), resourceGroupNameParam, virtualWANNameParam, body, nil) 98 if respErr := server.GetError(errRespr, req); respErr != nil { 99 return nil, respErr 100 } 101 beginDownload = &respr 102 v.beginDownload.add(req, beginDownload) 103 } 104 105 resp, err := server.PollerResponderNext(beginDownload, req) 106 if err != nil { 107 return nil, err 108 } 109 110 if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) { 111 v.beginDownload.remove(req) 112 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)} 113 } 114 if !server.PollerResponderMore(beginDownload) { 115 v.beginDownload.remove(req) 116 } 117 118 return resp, nil 119 }