github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/virtualhubbgpconnection_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 // VirtualHubBgpConnectionServer is a fake server for instances of the armnetwork.VirtualHubBgpConnectionClient type. 25 type VirtualHubBgpConnectionServer struct { 26 // BeginCreateOrUpdate is the fake for method VirtualHubBgpConnectionClient.BeginCreateOrUpdate 27 // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated 28 BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, parameters armnetwork.BgpConnection, options *armnetwork.VirtualHubBgpConnectionClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) 29 30 // BeginDelete is the fake for method VirtualHubBgpConnectionClient.BeginDelete 31 // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent 32 BeginDelete func(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, options *armnetwork.VirtualHubBgpConnectionClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionClientDeleteResponse], errResp azfake.ErrorResponder) 33 34 // Get is the fake for method VirtualHubBgpConnectionClient.Get 35 // HTTP status codes to indicate success: http.StatusOK 36 Get func(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, options *armnetwork.VirtualHubBgpConnectionClientGetOptions) (resp azfake.Responder[armnetwork.VirtualHubBgpConnectionClientGetResponse], errResp azfake.ErrorResponder) 37 } 38 39 // NewVirtualHubBgpConnectionServerTransport creates a new instance of VirtualHubBgpConnectionServerTransport with the provided implementation. 40 // The returned VirtualHubBgpConnectionServerTransport instance is connected to an instance of armnetwork.VirtualHubBgpConnectionClient via the 41 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 42 func NewVirtualHubBgpConnectionServerTransport(srv *VirtualHubBgpConnectionServer) *VirtualHubBgpConnectionServerTransport { 43 return &VirtualHubBgpConnectionServerTransport{ 44 srv: srv, 45 beginCreateOrUpdate: newTracker[azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionClientCreateOrUpdateResponse]](), 46 beginDelete: newTracker[azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionClientDeleteResponse]](), 47 } 48 } 49 50 // VirtualHubBgpConnectionServerTransport connects instances of armnetwork.VirtualHubBgpConnectionClient to instances of VirtualHubBgpConnectionServer. 51 // Don't use this type directly, use NewVirtualHubBgpConnectionServerTransport instead. 52 type VirtualHubBgpConnectionServerTransport struct { 53 srv *VirtualHubBgpConnectionServer 54 beginCreateOrUpdate *tracker[azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionClientCreateOrUpdateResponse]] 55 beginDelete *tracker[azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionClientDeleteResponse]] 56 } 57 58 // Do implements the policy.Transporter interface for VirtualHubBgpConnectionServerTransport. 59 func (v *VirtualHubBgpConnectionServerTransport) Do(req *http.Request) (*http.Response, error) { 60 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 61 method, ok := rawMethod.(string) 62 if !ok { 63 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 64 } 65 66 var resp *http.Response 67 var err error 68 69 switch method { 70 case "VirtualHubBgpConnectionClient.BeginCreateOrUpdate": 71 resp, err = v.dispatchBeginCreateOrUpdate(req) 72 case "VirtualHubBgpConnectionClient.BeginDelete": 73 resp, err = v.dispatchBeginDelete(req) 74 case "VirtualHubBgpConnectionClient.Get": 75 resp, err = v.dispatchGet(req) 76 default: 77 err = fmt.Errorf("unhandled API %s", method) 78 } 79 80 if err != nil { 81 return nil, err 82 } 83 84 return resp, nil 85 } 86 87 func (v *VirtualHubBgpConnectionServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) { 88 if v.srv.BeginCreateOrUpdate == nil { 89 return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")} 90 } 91 beginCreateOrUpdate := v.beginCreateOrUpdate.get(req) 92 if beginCreateOrUpdate == nil { 93 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/virtualHubs/(?P<virtualHubName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections/(?P<connectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 94 regex := regexp.MustCompile(regexStr) 95 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 96 if matches == nil || len(matches) < 4 { 97 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 98 } 99 body, err := server.UnmarshalRequestAsJSON[armnetwork.BgpConnection](req) 100 if err != nil { 101 return nil, err 102 } 103 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 104 if err != nil { 105 return nil, err 106 } 107 virtualHubNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) 108 if err != nil { 109 return nil, err 110 } 111 connectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) 112 if err != nil { 113 return nil, err 114 } 115 respr, errRespr := v.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, virtualHubNameParam, connectionNameParam, body, nil) 116 if respErr := server.GetError(errRespr, req); respErr != nil { 117 return nil, respErr 118 } 119 beginCreateOrUpdate = &respr 120 v.beginCreateOrUpdate.add(req, beginCreateOrUpdate) 121 } 122 123 resp, err := server.PollerResponderNext(beginCreateOrUpdate, req) 124 if err != nil { 125 return nil, err 126 } 127 128 if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) { 129 v.beginCreateOrUpdate.remove(req) 130 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)} 131 } 132 if !server.PollerResponderMore(beginCreateOrUpdate) { 133 v.beginCreateOrUpdate.remove(req) 134 } 135 136 return resp, nil 137 } 138 139 func (v *VirtualHubBgpConnectionServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { 140 if v.srv.BeginDelete == nil { 141 return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} 142 } 143 beginDelete := v.beginDelete.get(req) 144 if beginDelete == nil { 145 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/virtualHubs/(?P<virtualHubName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections/(?P<connectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 146 regex := regexp.MustCompile(regexStr) 147 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 148 if matches == nil || len(matches) < 4 { 149 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 150 } 151 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 152 if err != nil { 153 return nil, err 154 } 155 virtualHubNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) 156 if err != nil { 157 return nil, err 158 } 159 connectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) 160 if err != nil { 161 return nil, err 162 } 163 respr, errRespr := v.srv.BeginDelete(req.Context(), resourceGroupNameParam, virtualHubNameParam, connectionNameParam, nil) 164 if respErr := server.GetError(errRespr, req); respErr != nil { 165 return nil, respErr 166 } 167 beginDelete = &respr 168 v.beginDelete.add(req, beginDelete) 169 } 170 171 resp, err := server.PollerResponderNext(beginDelete, req) 172 if err != nil { 173 return nil, err 174 } 175 176 if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { 177 v.beginDelete.remove(req) 178 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} 179 } 180 if !server.PollerResponderMore(beginDelete) { 181 v.beginDelete.remove(req) 182 } 183 184 return resp, nil 185 } 186 187 func (v *VirtualHubBgpConnectionServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { 188 if v.srv.Get == nil { 189 return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} 190 } 191 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/virtualHubs/(?P<virtualHubName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections/(?P<connectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 192 regex := regexp.MustCompile(regexStr) 193 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 194 if matches == nil || len(matches) < 4 { 195 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 196 } 197 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 198 if err != nil { 199 return nil, err 200 } 201 virtualHubNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")]) 202 if err != nil { 203 return nil, err 204 } 205 connectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")]) 206 if err != nil { 207 return nil, err 208 } 209 respr, errRespr := v.srv.Get(req.Context(), resourceGroupNameParam, virtualHubNameParam, connectionNameParam, nil) 210 if respErr := server.GetError(errRespr, req); respErr != nil { 211 return nil, respErr 212 } 213 respContent := server.GetResponseContent(respr) 214 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 215 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 216 } 217 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).BgpConnection, req) 218 if err != nil { 219 return nil, err 220 } 221 return resp, nil 222 }