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