github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/serviceassociationlinks_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 // ServiceAssociationLinksServer is a fake server for instances of the armnetwork.ServiceAssociationLinksClient type. 25 type ServiceAssociationLinksServer struct { 26 // List is the fake for method ServiceAssociationLinksClient.List 27 // HTTP status codes to indicate success: http.StatusOK 28 List func(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, options *armnetwork.ServiceAssociationLinksClientListOptions) (resp azfake.Responder[armnetwork.ServiceAssociationLinksClientListResponse], errResp azfake.ErrorResponder) 29 } 30 31 // NewServiceAssociationLinksServerTransport creates a new instance of ServiceAssociationLinksServerTransport with the provided implementation. 32 // The returned ServiceAssociationLinksServerTransport instance is connected to an instance of armnetwork.ServiceAssociationLinksClient via the 33 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 34 func NewServiceAssociationLinksServerTransport(srv *ServiceAssociationLinksServer) *ServiceAssociationLinksServerTransport { 35 return &ServiceAssociationLinksServerTransport{srv: srv} 36 } 37 38 // ServiceAssociationLinksServerTransport connects instances of armnetwork.ServiceAssociationLinksClient to instances of ServiceAssociationLinksServer. 39 // Don't use this type directly, use NewServiceAssociationLinksServerTransport instead. 40 type ServiceAssociationLinksServerTransport struct { 41 srv *ServiceAssociationLinksServer 42 } 43 44 // Do implements the policy.Transporter interface for ServiceAssociationLinksServerTransport. 45 func (s *ServiceAssociationLinksServerTransport) Do(req *http.Request) (*http.Response, error) { 46 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 47 method, ok := rawMethod.(string) 48 if !ok { 49 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 50 } 51 52 var resp *http.Response 53 var err error 54 55 switch method { 56 case "ServiceAssociationLinksClient.List": 57 resp, err = s.dispatchList(req) 58 default: 59 err = fmt.Errorf("unhandled API %s", method) 60 } 61 62 if err != nil { 63 return nil, err 64 } 65 66 return resp, nil 67 } 68 69 func (s *ServiceAssociationLinksServerTransport) dispatchList(req *http.Request) (*http.Response, error) { 70 if s.srv.List == nil { 71 return nil, &nonRetriableError{errors.New("fake for method List not implemented")} 72 } 73 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/virtualNetworks/(?P<virtualNetworkName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/subnets/(?P<subnetName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ServiceAssociationLinks` 74 regex := regexp.MustCompile(regexStr) 75 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 76 if matches == nil || len(matches) < 4 { 77 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 78 } 79 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 80 if err != nil { 81 return nil, err 82 } 83 virtualNetworkNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("virtualNetworkName")]) 84 if err != nil { 85 return nil, err 86 } 87 subnetNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("subnetName")]) 88 if err != nil { 89 return nil, err 90 } 91 respr, errRespr := s.srv.List(req.Context(), resourceGroupNameParam, virtualNetworkNameParam, subnetNameParam, nil) 92 if respErr := server.GetError(errRespr, req); respErr != nil { 93 return nil, respErr 94 } 95 respContent := server.GetResponseContent(respr) 96 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 97 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 98 } 99 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ServiceAssociationLinksListResult, req) 100 if err != nil { 101 return nil, err 102 } 103 return resp, nil 104 }