github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/virtualapplianceskus_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 // VirtualApplianceSKUsServer is a fake server for instances of the armnetwork.VirtualApplianceSKUsClient type. 26 type VirtualApplianceSKUsServer struct { 27 // Get is the fake for method VirtualApplianceSKUsClient.Get 28 // HTTP status codes to indicate success: http.StatusOK 29 Get func(ctx context.Context, skuName string, options *armnetwork.VirtualApplianceSKUsClientGetOptions) (resp azfake.Responder[armnetwork.VirtualApplianceSKUsClientGetResponse], errResp azfake.ErrorResponder) 30 31 // NewListPager is the fake for method VirtualApplianceSKUsClient.NewListPager 32 // HTTP status codes to indicate success: http.StatusOK 33 NewListPager func(options *armnetwork.VirtualApplianceSKUsClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualApplianceSKUsClientListResponse]) 34 } 35 36 // NewVirtualApplianceSKUsServerTransport creates a new instance of VirtualApplianceSKUsServerTransport with the provided implementation. 37 // The returned VirtualApplianceSKUsServerTransport instance is connected to an instance of armnetwork.VirtualApplianceSKUsClient via the 38 // azcore.ClientOptions.Transporter field in the client's constructor parameters. 39 func NewVirtualApplianceSKUsServerTransport(srv *VirtualApplianceSKUsServer) *VirtualApplianceSKUsServerTransport { 40 return &VirtualApplianceSKUsServerTransport{ 41 srv: srv, 42 newListPager: newTracker[azfake.PagerResponder[armnetwork.VirtualApplianceSKUsClientListResponse]](), 43 } 44 } 45 46 // VirtualApplianceSKUsServerTransport connects instances of armnetwork.VirtualApplianceSKUsClient to instances of VirtualApplianceSKUsServer. 47 // Don't use this type directly, use NewVirtualApplianceSKUsServerTransport instead. 48 type VirtualApplianceSKUsServerTransport struct { 49 srv *VirtualApplianceSKUsServer 50 newListPager *tracker[azfake.PagerResponder[armnetwork.VirtualApplianceSKUsClientListResponse]] 51 } 52 53 // Do implements the policy.Transporter interface for VirtualApplianceSKUsServerTransport. 54 func (v *VirtualApplianceSKUsServerTransport) Do(req *http.Request) (*http.Response, error) { 55 rawMethod := req.Context().Value(runtime.CtxAPINameKey{}) 56 method, ok := rawMethod.(string) 57 if !ok { 58 return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")} 59 } 60 61 var resp *http.Response 62 var err error 63 64 switch method { 65 case "VirtualApplianceSKUsClient.Get": 66 resp, err = v.dispatchGet(req) 67 case "VirtualApplianceSKUsClient.NewListPager": 68 resp, err = v.dispatchNewListPager(req) 69 default: 70 err = fmt.Errorf("unhandled API %s", method) 71 } 72 73 if err != nil { 74 return nil, err 75 } 76 77 return resp, nil 78 } 79 80 func (v *VirtualApplianceSKUsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) { 81 if v.srv.Get == nil { 82 return nil, &nonRetriableError{errors.New("fake for method Get not implemented")} 83 } 84 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkVirtualApplianceSkus/(?P<skuName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)` 85 regex := regexp.MustCompile(regexStr) 86 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 87 if matches == nil || len(matches) < 2 { 88 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 89 } 90 skuNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("skuName")]) 91 if err != nil { 92 return nil, err 93 } 94 respr, errRespr := v.srv.Get(req.Context(), skuNameParam, nil) 95 if respErr := server.GetError(errRespr, req); respErr != nil { 96 return nil, respErr 97 } 98 respContent := server.GetResponseContent(respr) 99 if !contains([]int{http.StatusOK}, respContent.HTTPStatus) { 100 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)} 101 } 102 resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).VirtualApplianceSKU, req) 103 if err != nil { 104 return nil, err 105 } 106 return resp, nil 107 } 108 109 func (v *VirtualApplianceSKUsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) { 110 if v.srv.NewListPager == nil { 111 return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")} 112 } 113 newListPager := v.newListPager.get(req) 114 if newListPager == nil { 115 const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkVirtualApplianceSkus` 116 regex := regexp.MustCompile(regexStr) 117 matches := regex.FindStringSubmatch(req.URL.EscapedPath()) 118 if matches == nil || len(matches) < 1 { 119 return nil, fmt.Errorf("failed to parse path %s", req.URL.Path) 120 } 121 resp := v.srv.NewListPager(nil) 122 newListPager = &resp 123 v.newListPager.add(req, newListPager) 124 server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.VirtualApplianceSKUsClientListResponse, createLink func() string) { 125 page.NextLink = to.Ptr(createLink()) 126 }) 127 } 128 resp, err := server.PagerResponderNext(newListPager, req) 129 if err != nil { 130 return nil, err 131 } 132 if !contains([]int{http.StatusOK}, resp.StatusCode) { 133 v.newListPager.remove(req) 134 return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)} 135 } 136 if !server.PagerResponderMore(newListPager) { 137 v.newListPager.remove(req) 138 } 139 return resp, nil 140 }