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