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