github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/bgpservicecommunities_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 "errors" 13 "fmt" 14 azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" 18 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6" 19 "net/http" 20 "regexp" 21 ) 22 23 // BgpServiceCommunitiesServer is a fake server for instances of the armnetwork.BgpServiceCommunitiesClient type. 24 type BgpServiceCommunitiesServer struct { 25 // NewListPager is the fake for method BgpServiceCommunitiesClient.NewListPager 26 // HTTP status codes to indicate success: http.StatusOK 27 NewListPager func(options *armnetwork.BgpServiceCommunitiesClientListOptions) (resp azfake.PagerResponder[armnetwork.BgpServiceCommunitiesClientListResponse]) 28 } 29 30 // NewBgpServiceCommunitiesServerTransport creates a new instance of BgpServiceCommunitiesServerTransport with the provided implementation. 31 // The returned BgpServiceCommunitiesServerTransport instance is connected to an instance of armnetwork.BgpServiceCommunitiesClient via the 32 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 33 func NewBgpServiceCommunitiesServerTransport(srv *BgpServiceCommunitiesServer) *BgpServiceCommunitiesServerTransport { 34 return &BgpServiceCommunitiesServerTransport{ 35 srv: srv, 36 newListPager: newTracker[azfake.PagerResponder[armnetwork.BgpServiceCommunitiesClientListResponse]](), 37 } 38 } 39 40 // BgpServiceCommunitiesServerTransport connects instances of armnetwork.BgpServiceCommunitiesClient to instances of BgpServiceCommunitiesServer. 41 // Don't use this type directly, use NewBgpServiceCommunitiesServerTransport instead. 42 type BgpServiceCommunitiesServerTransport struct { 43 srv *BgpServiceCommunitiesServer 44 newListPager *tracker[azfake.PagerResponder[armnetwork.BgpServiceCommunitiesClientListResponse]] 45 } 46 47 // Do implements the policy.Transporter interface for BgpServiceCommunitiesServerTransport. 48 func (b *BgpServiceCommunitiesServerTransport) Do(req *http.Request) (*http.Response, error) { 49 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 50 method, ok := rawMethod.(string) 51 if !ok { 52 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 53 } 54 55 var resp *http.Response 56 var err error 57 58 switch method { 59 case "BgpServiceCommunitiesClient.NewListPager": 60 resp, err = b.dispatchNewListPager(req) 61 default: 62 err = fmt.Errorf("unhandled API %s", method) 63 } 64 65 if err != nil { 66 return nil, err 67 } 68 69 return resp, nil 70 } 71 72 func (b *BgpServiceCommunitiesServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { 73 if b.srv.NewListPager == nil { 74 return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} 75 } 76 newListPager := b.newListPager.get(req) 77 if newListPager == nil { 78 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/bgpServiceCommunities` 79 regex := regexp.MustCompile(regexStr) 80 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 81 if matches == nil || len(matches) < 1 { 82 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 83 } 84 resp := b.srv.NewListPager(nil) 85 newListPager = &resp 86 b.newListPager.add(req, newListPager) 87 server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.BgpServiceCommunitiesClientListResponse, createLink func() string) { 88 page.NextLink = to.Ptr(createLink()) 89 }) 90 } 91 resp, err := server.PagerResponderNext(newListPager, req) 92 if err != nil { 93 return nil, err 94 } 95 if !contains([]int{http.StatusOK}, resp.StatusCode) { 96 b.newListPager.remove(req) 97 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} 98 } 99 if !server.PagerResponderMore(newListPager) { 100 b.newListPager.remove(req) 101 } 102 return resp, nil 103 }