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