github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/routingrulecollections_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 "strconv" 24 ) 25 26 // RoutingRuleCollectionsServer is a fake server for instances of the armnetwork.RoutingRuleCollectionsClient type. 27 type RoutingRuleCollectionsServer struct { 28 // CreateOrUpdate is the fake for method RoutingRuleCollectionsClient.CreateOrUpdate 29 // HTTP status codes to indicate success: http.StatusOK, http.StatusCreated 30 CreateOrUpdate func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleCollection armnetwork.RoutingRuleCollection, options *armnetwork.RoutingRuleCollectionsClientCreateOrUpdateOptions) (resp azfake.Responder[armnetwork.RoutingRuleCollectionsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) 31 32 // BeginDelete is the fake for method RoutingRuleCollectionsClient.BeginDelete 33 // HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent 34 BeginDelete func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *armnetwork.RoutingRuleCollectionsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.RoutingRuleCollectionsClientDeleteResponse], errResp azfake.ErrorResponder) 35 36 // Get is the fake for method RoutingRuleCollectionsClient.Get 37 // HTTP status codes to indicate success: http.StatusOK 38 Get func(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *armnetwork.RoutingRuleCollectionsClientGetOptions) (resp azfake.Responder[armnetwork.RoutingRuleCollectionsClientGetResponse], errResp azfake.ErrorResponder) 39 40 // NewListPager is the fake for method RoutingRuleCollectionsClient.NewListPager 41 // HTTP status codes to indicate success: http.StatusOK 42 NewListPager func(resourceGroupName string, networkManagerName string, configurationName string, options *armnetwork.RoutingRuleCollectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.RoutingRuleCollectionsClientListResponse]) 43 } 44 45 // NewRoutingRuleCollectionsServerTransport creates a new instance of RoutingRuleCollectionsServerTransport with the provided implementation. 46 // The returned RoutingRuleCollectionsServerTransport instance is connected to an instance of armnetwork.RoutingRuleCollectionsClient via the 47 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 48 func NewRoutingRuleCollectionsServerTransport(srv *RoutingRuleCollectionsServer) *RoutingRuleCollectionsServerTransport { 49 return &RoutingRuleCollectionsServerTransport{ 50 srv: srv, 51 beginDelete: newTracker[azfake.PollerResponder[armnetwork.RoutingRuleCollectionsClientDeleteResponse]](), 52 newListPager: newTracker[azfake.PagerResponder[armnetwork.RoutingRuleCollectionsClientListResponse]](), 53 } 54 } 55 56 // RoutingRuleCollectionsServerTransport connects instances of armnetwork.RoutingRuleCollectionsClient to instances of RoutingRuleCollectionsServer. 57 // Don't use this type directly, use NewRoutingRuleCollectionsServerTransport instead. 58 type RoutingRuleCollectionsServerTransport struct { 59 srv *RoutingRuleCollectionsServer 60 beginDelete *tracker[azfake.PollerResponder[armnetwork.RoutingRuleCollectionsClientDeleteResponse]] 61 newListPager *tracker[azfake.PagerResponder[armnetwork.RoutingRuleCollectionsClientListResponse]] 62 } 63 64 // Do implements the policy.Transporter interface for RoutingRuleCollectionsServerTransport. 65 func (r *RoutingRuleCollectionsServerTransport) Do(req *http.Request) (*http.Response, error) { 66 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 67 method, ok := rawMethod.(string) 68 if !ok { 69 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 70 } 71 72 var resp *http.Response 73 var err error 74 75 switch method { 76 case "RoutingRuleCollectionsClient.CreateOrUpdate": 77 resp, err = r.dispatchCreateOrUpdate(req) 78 case "RoutingRuleCollectionsClient.BeginDelete": 79 resp, err = r.dispatchBeginDelete(req) 80 case "RoutingRuleCollectionsClient.Get": 81 resp, err = r.dispatchGet(req) 82 case "RoutingRuleCollectionsClient.NewListPager": 83 resp, err = r.dispatchNewListPager(req) 84 default: 85 err = fmt.Errorf("unhandled API %s", method) 86 } 87 88 if err != nil { 89 return nil, err 90 } 91 92 return resp, nil 93 } 94 95 func (r *RoutingRuleCollectionsServerTransport) dispatchCreateOrUpdate(req *http.Request) (*http.Response, error) { 96 if r.srv.CreateOrUpdate == nil { 97 return nil, &nonRetriableError{errors.New("fake for method CreateOrUpdate not implemented")} 98 } 99 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkManagers/(?P<networkManagerName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routingConfigurations/(?P<configurationName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections/(?P<ruleCollectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 100 regex := regexp.MustCompile(regexStr) 101 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 102 if matches == nil || len(matches) < 5 { 103 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 104 } 105 body, err := server.UnmarshalRequestAsJSON[armnetwork.RoutingRuleCollection](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 networkManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) 114 if err != nil { 115 return nil, err 116 } 117 configurationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) 118 if err != nil { 119 return nil, err 120 } 121 ruleCollectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) 122 if err != nil { 123 return nil, err 124 } 125 respr, errRespr := r.srv.CreateOrUpdate(req.Context(), resourceGroupNameParam, networkManagerNameParam, configurationNameParam, ruleCollectionNameParam, body, nil) 126 if respErr := server.GetError(errRespr, req); respErr != nil { 127 return nil, respErr 128 } 129 respContent := server.GetResponseContent(respr) 130 if !contains([]int{http.StatusOK, http.StatusCreated}, respContent.HTTPStatus) { 131 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", respContent.HTTPStatus)} 132 } 133 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).RoutingRuleCollection, req) 134 if err != nil { 135 return nil, err 136 } 137 return resp, nil 138 } 139 140 func (r *RoutingRuleCollectionsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) { 141 if r.srv.BeginDelete == nil { 142 return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")} 143 } 144 beginDelete := r.beginDelete.get(req) 145 if beginDelete == nil { 146 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkManagers/(?P<networkManagerName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routingConfigurations/(?P<configurationName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections/(?P<ruleCollectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 147 regex := regexp.MustCompile(regexStr) 148 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 149 if matches == nil || len(matches) < 5 { 150 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 151 } 152 qp := req.URL.Query() 153 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 154 if err != nil { 155 return nil, err 156 } 157 networkManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) 158 if err != nil { 159 return nil, err 160 } 161 configurationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) 162 if err != nil { 163 return nil, err 164 } 165 ruleCollectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) 166 if err != nil { 167 return nil, err 168 } 169 forceUnescaped, err := url.QueryUnescape(qp.Get("force")) 170 if err != nil { 171 return nil, err 172 } 173 forceParam, err := parseOptional(forceUnescaped, strconv.ParseBool) 174 if err != nil { 175 return nil, err 176 } 177 var options *armnetwork.RoutingRuleCollectionsClientBeginDeleteOptions 178 if forceParam != nil { 179 options = &armnetwork.RoutingRuleCollectionsClientBeginDeleteOptions{ 180 Force: forceParam, 181 } 182 } 183 respr, errRespr := r.srv.BeginDelete(req.Context(), resourceGroupNameParam, networkManagerNameParam, configurationNameParam, ruleCollectionNameParam, options) 184 if respErr := server.GetError(errRespr, req); respErr != nil { 185 return nil, respErr 186 } 187 beginDelete = &respr 188 r.beginDelete.add(req, beginDelete) 189 } 190 191 resp, err := server.PollerResponderNext(beginDelete, req) 192 if err != nil { 193 return nil, err 194 } 195 196 if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) { 197 r.beginDelete.remove(req) 198 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)} 199 } 200 if !server.PollerResponderMore(beginDelete) { 201 r.beginDelete.remove(req) 202 } 203 204 return resp, nil 205 } 206 207 func (r *RoutingRuleCollectionsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { 208 if r.srv.Get == nil { 209 return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} 210 } 211 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkManagers/(?P<networkManagerName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routingConfigurations/(?P<configurationName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections/(?P<ruleCollectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 212 regex := regexp.MustCompile(regexStr) 213 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 214 if matches == nil || len(matches) < 5 { 215 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 216 } 217 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 218 if err != nil { 219 return nil, err 220 } 221 networkManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) 222 if err != nil { 223 return nil, err 224 } 225 configurationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) 226 if err != nil { 227 return nil, err 228 } 229 ruleCollectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionName")]) 230 if err != nil { 231 return nil, err 232 } 233 respr, errRespr := r.srv.Get(req.Context(), resourceGroupNameParam, networkManagerNameParam, configurationNameParam, ruleCollectionNameParam, nil) 234 if respErr := server.GetError(errRespr, req); respErr != nil { 235 return nil, respErr 236 } 237 respContent := server.GetResponseContent(respr) 238 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 239 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 240 } 241 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).RoutingRuleCollection, req) 242 if err != nil { 243 return nil, err 244 } 245 return resp, nil 246 } 247 248 func (r *RoutingRuleCollectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { 249 if r.srv.NewListPager == nil { 250 return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} 251 } 252 newListPager := r.newListPager.get(req) 253 if newListPager == nil { 254 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkManagers/(?P<networkManagerName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/routingConfigurations/(?P<configurationName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollections` 255 regex := regexp.MustCompile(regexStr) 256 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 257 if matches == nil || len(matches) < 4 { 258 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 259 } 260 qp := req.URL.Query() 261 resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")]) 262 if err != nil { 263 return nil, err 264 } 265 networkManagerNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkManagerName")]) 266 if err != nil { 267 return nil, err 268 } 269 configurationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("configurationName")]) 270 if err != nil { 271 return nil, err 272 } 273 topUnescaped, err := url.QueryUnescape(qp.Get("$top")) 274 if err != nil { 275 return nil, err 276 } 277 topParam, err := parseOptional(topUnescaped, func(v string) (int32, error) { 278 p, parseErr := strconv.ParseInt(v, 10, 32) 279 if parseErr != nil { 280 return 0, parseErr 281 } 282 return int32(p), nil 283 }) 284 if err != nil { 285 return nil, err 286 } 287 skipTokenUnescaped, err := url.QueryUnescape(qp.Get("$skipToken")) 288 if err != nil { 289 return nil, err 290 } 291 skipTokenParam := getOptional(skipTokenUnescaped) 292 var options *armnetwork.RoutingRuleCollectionsClientListOptions 293 if topParam != nil || skipTokenParam != nil { 294 options = &armnetwork.RoutingRuleCollectionsClientListOptions{ 295 Top: topParam, 296 SkipToken: skipTokenParam, 297 } 298 } 299 resp := r.srv.NewListPager(resourceGroupNameParam, networkManagerNameParam, configurationNameParam, options) 300 newListPager = &resp 301 r.newListPager.add(req, newListPager) 302 server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.RoutingRuleCollectionsClientListResponse, createLink func() string) { 303 page.NextLink = to.Ptr(createLink()) 304 }) 305 } 306 resp, err := server.PagerResponderNext(newListPager, req) 307 if err != nil { 308 return nil, err 309 } 310 if !contains([]int{http.StatusOK}, resp.StatusCode) { 311 r.newListPager.remove(req) 312 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} 313 } 314 if !server.PagerResponderMore(newListPager) { 315 r.newListPager.remove(req) 316 } 317 return resp, nil 318 }