github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/expressroutegateways_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/resourcemanager/network/armnetwork/v6"
    19  	"net/http"
    20  	"net/url"
    21  	"regexp"
    22  )
    23  
    24  // ExpressRouteGatewaysServer is a fake server for instances of the armnetwork.ExpressRouteGatewaysClient type.
    25  type ExpressRouteGatewaysServer struct {
    26  	// BeginCreateOrUpdate is the fake for method ExpressRouteGatewaysClient.BeginCreateOrUpdate
    27  	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
    28  	BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, putExpressRouteGatewayParameters armnetwork.ExpressRouteGateway, options *armnetwork.ExpressRouteGatewaysClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientCreateOrUpdateResponse], errResp azfake.ErrorResponder)
    29  
    30  	// BeginDelete is the fake for method ExpressRouteGatewaysClient.BeginDelete
    31  	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
    32  	BeginDelete func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, options *armnetwork.ExpressRouteGatewaysClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientDeleteResponse], errResp azfake.ErrorResponder)
    33  
    34  	// Get is the fake for method ExpressRouteGatewaysClient.Get
    35  	// HTTP status codes to indicate success: http.StatusOK
    36  	Get func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, options *armnetwork.ExpressRouteGatewaysClientGetOptions) (resp azfake.Responder[armnetwork.ExpressRouteGatewaysClientGetResponse], errResp azfake.ErrorResponder)
    37  
    38  	// ListByResourceGroup is the fake for method ExpressRouteGatewaysClient.ListByResourceGroup
    39  	// HTTP status codes to indicate success: http.StatusOK
    40  	ListByResourceGroup func(ctx context.Context, resourceGroupName string, options *armnetwork.ExpressRouteGatewaysClientListByResourceGroupOptions) (resp azfake.Responder[armnetwork.ExpressRouteGatewaysClientListByResourceGroupResponse], errResp azfake.ErrorResponder)
    41  
    42  	// ListBySubscription is the fake for method ExpressRouteGatewaysClient.ListBySubscription
    43  	// HTTP status codes to indicate success: http.StatusOK
    44  	ListBySubscription func(ctx context.Context, options *armnetwork.ExpressRouteGatewaysClientListBySubscriptionOptions) (resp azfake.Responder[armnetwork.ExpressRouteGatewaysClientListBySubscriptionResponse], errResp azfake.ErrorResponder)
    45  
    46  	// BeginUpdateTags is the fake for method ExpressRouteGatewaysClient.BeginUpdateTags
    47  	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
    48  	BeginUpdateTags func(ctx context.Context, resourceGroupName string, expressRouteGatewayName string, expressRouteGatewayParameters armnetwork.TagsObject, options *armnetwork.ExpressRouteGatewaysClientBeginUpdateTagsOptions) (resp azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientUpdateTagsResponse], errResp azfake.ErrorResponder)
    49  }
    50  
    51  // NewExpressRouteGatewaysServerTransport creates a new instance of ExpressRouteGatewaysServerTransport with the provided implementation.
    52  // The returned ExpressRouteGatewaysServerTransport instance is connected to an instance of armnetwork.ExpressRouteGatewaysClient via the
    53  // azcore.ClientOptions.Transporter field in the client's constructor parameters.
    54  func NewExpressRouteGatewaysServerTransport(srv *ExpressRouteGatewaysServer) *ExpressRouteGatewaysServerTransport {
    55  	return &ExpressRouteGatewaysServerTransport{
    56  		srv:                 srv,
    57  		beginCreateOrUpdate: newTracker[azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientCreateOrUpdateResponse]](),
    58  		beginDelete:         newTracker[azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientDeleteResponse]](),
    59  		beginUpdateTags:     newTracker[azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientUpdateTagsResponse]](),
    60  	}
    61  }
    62  
    63  // ExpressRouteGatewaysServerTransport connects instances of armnetwork.ExpressRouteGatewaysClient to instances of ExpressRouteGatewaysServer.
    64  // Don't use this type directly, use NewExpressRouteGatewaysServerTransport instead.
    65  type ExpressRouteGatewaysServerTransport struct {
    66  	srv                 *ExpressRouteGatewaysServer
    67  	beginCreateOrUpdate *tracker[azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientCreateOrUpdateResponse]]
    68  	beginDelete         *tracker[azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientDeleteResponse]]
    69  	beginUpdateTags     *tracker[azfake.PollerResponder[armnetwork.ExpressRouteGatewaysClientUpdateTagsResponse]]
    70  }
    71  
    72  // Do implements the policy.Transporter interface for ExpressRouteGatewaysServerTransport.
    73  func (e *ExpressRouteGatewaysServerTransport) Do(req *http.Request) (*http.Response, error) {
    74  	rawMethod := req.Context().Value(runtime.CtxAPINameKey{})
    75  	method, ok := rawMethod.(string)
    76  	if !ok {
    77  		return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}
    78  	}
    79  
    80  	var resp *http.Response
    81  	var err error
    82  
    83  	switch method {
    84  	case "ExpressRouteGatewaysClient.BeginCreateOrUpdate":
    85  		resp, err = e.dispatchBeginCreateOrUpdate(req)
    86  	case "ExpressRouteGatewaysClient.BeginDelete":
    87  		resp, err = e.dispatchBeginDelete(req)
    88  	case "ExpressRouteGatewaysClient.Get":
    89  		resp, err = e.dispatchGet(req)
    90  	case "ExpressRouteGatewaysClient.ListByResourceGroup":
    91  		resp, err = e.dispatchListByResourceGroup(req)
    92  	case "ExpressRouteGatewaysClient.ListBySubscription":
    93  		resp, err = e.dispatchListBySubscription(req)
    94  	case "ExpressRouteGatewaysClient.BeginUpdateTags":
    95  		resp, err = e.dispatchBeginUpdateTags(req)
    96  	default:
    97  		err = fmt.Errorf("unhandled API %s", method)
    98  	}
    99  
   100  	if err != nil {
   101  		return nil, err
   102  	}
   103  
   104  	return resp, nil
   105  }
   106  
   107  func (e *ExpressRouteGatewaysServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) {
   108  	if e.srv.BeginCreateOrUpdate == nil {
   109  		return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")}
   110  	}
   111  	beginCreateOrUpdate := e.beginCreateOrUpdate.get(req)
   112  	if beginCreateOrUpdate == nil {
   113  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/expressRouteGateways/(?P<expressRouteGatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
   114  		regex := regexp.MustCompile(regexStr)
   115  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   116  		if matches == nil || len(matches) < 3 {
   117  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   118  		}
   119  		body, err := server.UnmarshalRequestAsJSON[armnetwork.ExpressRouteGateway](req)
   120  		if err != nil {
   121  			return nil, err
   122  		}
   123  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   124  		if err != nil {
   125  			return nil, err
   126  		}
   127  		expressRouteGatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")])
   128  		if err != nil {
   129  			return nil, err
   130  		}
   131  		respr, errRespr := e.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, expressRouteGatewayNameParam, body, nil)
   132  		if respErr := server.GetError(errRespr, req); respErr != nil {
   133  			return nil, respErr
   134  		}
   135  		beginCreateOrUpdate = &respr
   136  		e.beginCreateOrUpdate.add(req, beginCreateOrUpdate)
   137  	}
   138  
   139  	resp, err := server.PollerResponderNext(beginCreateOrUpdate, req)
   140  	if err != nil {
   141  		return nil, err
   142  	}
   143  
   144  	if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) {
   145  		e.beginCreateOrUpdate.remove(req)
   146  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)}
   147  	}
   148  	if !server.PollerResponderMore(beginCreateOrUpdate) {
   149  		e.beginCreateOrUpdate.remove(req)
   150  	}
   151  
   152  	return resp, nil
   153  }
   154  
   155  func (e *ExpressRouteGatewaysServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) {
   156  	if e.srv.BeginDelete == nil {
   157  		return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")}
   158  	}
   159  	beginDelete := e.beginDelete.get(req)
   160  	if beginDelete == nil {
   161  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/expressRouteGateways/(?P<expressRouteGatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
   162  		regex := regexp.MustCompile(regexStr)
   163  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   164  		if matches == nil || len(matches) < 3 {
   165  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   166  		}
   167  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   168  		if err != nil {
   169  			return nil, err
   170  		}
   171  		expressRouteGatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")])
   172  		if err != nil {
   173  			return nil, err
   174  		}
   175  		respr, errRespr := e.srv.BeginDelete(req.Context(), resourceGroupNameParam, expressRouteGatewayNameParam, nil)
   176  		if respErr := server.GetError(errRespr, req); respErr != nil {
   177  			return nil, respErr
   178  		}
   179  		beginDelete = &respr
   180  		e.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  		e.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  		e.beginDelete.remove(req)
   194  	}
   195  
   196  	return resp, nil
   197  }
   198  
   199  func (e *ExpressRouteGatewaysServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
   200  	if e.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/expressRouteGateways/(?P<expressRouteGatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
   204  	regex := regexp.MustCompile(regexStr)
   205  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   206  	if matches == nil || len(matches) < 3 {
   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  	expressRouteGatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")])
   214  	if err != nil {
   215  		return nil, err
   216  	}
   217  	respr, errRespr := e.srv.Get(req.Context(), resourceGroupNameParam, expressRouteGatewayNameParam, nil)
   218  	if respErr := server.GetError(errRespr, req); respErr != nil {
   219  		return nil, respErr
   220  	}
   221  	respContent := server.GetResponseContent(respr)
   222  	if !contains([]int{http.StatusOK}, respContent.HTTPStatus) {
   223  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)}
   224  	}
   225  	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ExpressRouteGateway, req)
   226  	if err != nil {
   227  		return nil, err
   228  	}
   229  	return resp, nil
   230  }
   231  
   232  func (e *ExpressRouteGatewaysServerTransport) dispatchListByResourceGroup(req *http.Request) (*http.Response, error) {
   233  	if e.srv.ListByResourceGroup == nil {
   234  		return nil, &nonRetriableError{errors.New("fake for method ListByResourceGroup not implemented")}
   235  	}
   236  	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/expressRouteGateways`
   237  	regex := regexp.MustCompile(regexStr)
   238  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   239  	if matches == nil || len(matches) < 2 {
   240  		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   241  	}
   242  	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   243  	if err != nil {
   244  		return nil, err
   245  	}
   246  	respr, errRespr := e.srv.ListByResourceGroup(req.Context(), resourceGroupNameParam, nil)
   247  	if respErr := server.GetError(errRespr, req); respErr != nil {
   248  		return nil, respErr
   249  	}
   250  	respContent := server.GetResponseContent(respr)
   251  	if !contains([]int{http.StatusOK}, respContent.HTTPStatus) {
   252  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)}
   253  	}
   254  	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ExpressRouteGatewayList, req)
   255  	if err != nil {
   256  		return nil, err
   257  	}
   258  	return resp, nil
   259  }
   260  
   261  func (e *ExpressRouteGatewaysServerTransport) dispatchListBySubscription(req *http.Request) (*http.Response, error) {
   262  	if e.srv.ListBySubscription == nil {
   263  		return nil, &nonRetriableError{errors.New("fake for method ListBySubscription not implemented")}
   264  	}
   265  	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/expressRouteGateways`
   266  	regex := regexp.MustCompile(regexStr)
   267  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   268  	if matches == nil || len(matches) < 1 {
   269  		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   270  	}
   271  	respr, errRespr := e.srv.ListBySubscription(req.Context(), nil)
   272  	if respErr := server.GetError(errRespr, req); respErr != nil {
   273  		return nil, respErr
   274  	}
   275  	respContent := server.GetResponseContent(respr)
   276  	if !contains([]int{http.StatusOK}, respContent.HTTPStatus) {
   277  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)}
   278  	}
   279  	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).ExpressRouteGatewayList, req)
   280  	if err != nil {
   281  		return nil, err
   282  	}
   283  	return resp, nil
   284  }
   285  
   286  func (e *ExpressRouteGatewaysServerTransport) dispatchBeginUpdateTags(req *http.Request) (*http.Response, error) {
   287  	if e.srv.BeginUpdateTags == nil {
   288  		return nil, &nonRetriableError{errors.New("fake for method BeginUpdateTags not implemented")}
   289  	}
   290  	beginUpdateTags := e.beginUpdateTags.get(req)
   291  	if beginUpdateTags == nil {
   292  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/expressRouteGateways/(?P<expressRouteGatewayName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
   293  		regex := regexp.MustCompile(regexStr)
   294  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   295  		if matches == nil || len(matches) < 3 {
   296  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   297  		}
   298  		body, err := server.UnmarshalRequestAsJSON[armnetwork.TagsObject](req)
   299  		if err != nil {
   300  			return nil, err
   301  		}
   302  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   303  		if err != nil {
   304  			return nil, err
   305  		}
   306  		expressRouteGatewayNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("expressRouteGatewayName")])
   307  		if err != nil {
   308  			return nil, err
   309  		}
   310  		respr, errRespr := e.srv.BeginUpdateTags(req.Context(), resourceGroupNameParam, expressRouteGatewayNameParam, body, nil)
   311  		if respErr := server.GetError(errRespr, req); respErr != nil {
   312  			return nil, respErr
   313  		}
   314  		beginUpdateTags = &respr
   315  		e.beginUpdateTags.add(req, beginUpdateTags)
   316  	}
   317  
   318  	resp, err := server.PollerResponderNext(beginUpdateTags, req)
   319  	if err != nil {
   320  		return nil, err
   321  	}
   322  
   323  	if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
   324  		e.beginUpdateTags.remove(req)
   325  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
   326  	}
   327  	if !server.PollerResponderMore(beginUpdateTags) {
   328  		e.beginUpdateTags.remove(req)
   329  	}
   330  
   331  	return resp, nil
   332  }