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