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