github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/loadbalanceroutboundrules_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 "regexp" 23 ) 24 25 // LoadBalancerOutboundRulesServer is a fake server for instances of the armnetwork.LoadBalancerOutboundRulesClient type. 26 type LoadBalancerOutboundRulesServer struct { 27 // Get is the fake for method LoadBalancerOutboundRulesClient.Get 28 // HTTP status codes to indicate success: http.StatusOK 29 Get func(ctx context.Context, resourceGroupName string, loadBalancerName string, outboundRuleName string, options *armnetwork.LoadBalancerOutboundRulesClientGetOptions) (resp azfake.Responder[armnetwork.LoadBalancerOutboundRulesClientGetResponse], errResp azfake.ErrorResponder) 30 31 // NewListPager is the fake for method LoadBalancerOutboundRulesClient.NewListPager 32 // HTTP status codes to indicate success: http.StatusOK 33 NewListPager func(resourceGroupName string, loadBalancerName string, options *armnetwork.LoadBalancerOutboundRulesClientListOptions) (resp azfake.PagerResponder[armnetwork.LoadBalancerOutboundRulesClientListResponse]) 34 } 35 36 // NewLoadBalancerOutboundRulesServerTransport creates a new instance of LoadBalancerOutboundRulesServerTransport with the provided implementation. 37 // The returned LoadBalancerOutboundRulesServerTransport instance is connected to an instance of armnetwork.LoadBalancerOutboundRulesClient via the 38 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 39 func NewLoadBalancerOutboundRulesServerTransport(srv *LoadBalancerOutboundRulesServer) *LoadBalancerOutboundRulesServerTransport { 40 return &LoadBalancerOutboundRulesServerTransport{ 41 srv: srv, 42 newListPager: newTracker[azfake.PagerResponder[armnetwork.LoadBalancerOutboundRulesClientListResponse]](), 43 } 44 } 45 46 // LoadBalancerOutboundRulesServerTransport connects instances of armnetwork.LoadBalancerOutboundRulesClient to instances of LoadBalancerOutboundRulesServer. 47 // Don't use this type directly, use NewLoadBalancerOutboundRulesServerTransport instead. 48 type LoadBalancerOutboundRulesServerTransport struct { 49 srv *LoadBalancerOutboundRulesServer 50 newListPager *tracker[azfake.PagerResponder[armnetwork.LoadBalancerOutboundRulesClientListResponse]] 51 } 52 53 // Do implements the policy.Transporter interface for LoadBalancerOutboundRulesServerTransport. 54 func (l *LoadBalancerOutboundRulesServerTransport) Do(req *http.Request) (*http.Response, error) { 55 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 56 method, ok := rawMethod.(string) 57 if !ok { 58 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 59 } 60 61 var resp *http.Response 62 var err error 63 64 switch method { 65 case "LoadBalancerOutboundRulesClient.Get": 66 resp, err = l.dispatchGet(req) 67 case "LoadBalancerOutboundRulesClient.NewListPager": 68 resp, err = l.dispatchNewListPager(req) 69 default: 70 err = fmt.Errorf("unhandled API %s", method) 71 } 72 73 if err != nil { 74 return nil, err 75 } 76 77 return resp, nil 78 } 79 80 func (l *LoadBalancerOutboundRulesServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { 81 if l.srv.Get == nil { 82 return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} 83 } 84 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/loadBalancers/(?P<loadBalancerName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/outboundRules/(?P<outboundRuleName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 85 regex := regexp.MustCompile(regexStr) 86 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 87 if matches == nil || len(matches) < 4 { 88 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 89 } 90 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 91 if err != nil { 92 return nil, err 93 } 94 loadBalancerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) 95 if err != nil { 96 return nil, err 97 } 98 outboundRuleNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("outboundRuleName")]) 99 if err != nil { 100 return nil, err 101 } 102 respr, errRespr := l.srv.Get(req.Context(), resourceGroupNameParam, loadBalancerNameParam, outboundRuleNameParam, nil) 103 if respErr := server.GetError(errRespr, req); respErr != nil { 104 return nil, respErr 105 } 106 respContent := server.GetResponseContent(respr) 107 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 108 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 109 } 110 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).OutboundRule, req) 111 if err != nil { 112 return nil, err 113 } 114 return resp, nil 115 } 116 117 func (l *LoadBalancerOutboundRulesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { 118 if l.srv.NewListPager == nil { 119 return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} 120 } 121 newListPager := l.newListPager.get(req) 122 if newListPager == nil { 123 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/loadBalancers/(?P<loadBalancerName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/outboundRules` 124 regex := regexp.MustCompile(regexStr) 125 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 126 if matches == nil || len(matches) < 3 { 127 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 128 } 129 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 130 if err != nil { 131 return nil, err 132 } 133 loadBalancerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("loadBalancerName")]) 134 if err != nil { 135 return nil, err 136 } 137 resp := l.srv.NewListPager(resourceGroupNameParam, loadBalancerNameParam, nil) 138 newListPager = &resp 139 l.newListPager.add(req, newListPager) 140 server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.LoadBalancerOutboundRulesClientListResponse, createLink func() string) { 141 page.NextLink = to.Ptr(createLink()) 142 }) 143 } 144 resp, err := server.PagerResponderNext(newListPager, req) 145 if err != nil { 146 return nil, err 147 } 148 if !contains([]int{http.StatusOK}, resp.StatusCode) { 149 l.newListPager.remove(req) 150 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} 151 } 152 if !server.PagerResponderMore(newListPager) { 153 l.newListPager.remove(req) 154 } 155 return resp, nil 156 }