github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/vpnserverconfigurationsassociatedwithvirtualwan_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  // VPNServerConfigurationsAssociatedWithVirtualWanServer is a fake server for instances of the armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClient type.
    25  type VPNServerConfigurationsAssociatedWithVirtualWanServer struct {
    26  	// BeginList is the fake for method VPNServerConfigurationsAssociatedWithVirtualWanClient.BeginList
    27  	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
    28  	BeginList func(ctx context.Context, resourceGroupName string, virtualWANName string, options *armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClientBeginListOptions) (resp azfake.PollerResponder[armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClientListResponse], errResp azfake.ErrorResponder)
    29  }
    30  
    31  // NewVPNServerConfigurationsAssociatedWithVirtualWanServerTransport creates a new instance of VPNServerConfigurationsAssociatedWithVirtualWanServerTransport with the provided implementation.
    32  // The returned VPNServerConfigurationsAssociatedWithVirtualWanServerTransport instance is connected to an instance of armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClient via the
    33  // azcore.ClientOptions.Transporter field in the client's constructor parameters.
    34  func NewVPNServerConfigurationsAssociatedWithVirtualWanServerTransport(srv *VPNServerConfigurationsAssociatedWithVirtualWanServer) *VPNServerConfigurationsAssociatedWithVirtualWanServerTransport {
    35  	return &VPNServerConfigurationsAssociatedWithVirtualWanServerTransport{
    36  		srv:       srv,
    37  		beginList: newTracker[azfake.PollerResponder[armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClientListResponse]](),
    38  	}
    39  }
    40  
    41  // VPNServerConfigurationsAssociatedWithVirtualWanServerTransport connects instances of armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClient to instances of VPNServerConfigurationsAssociatedWithVirtualWanServer.
    42  // Don't use this type directly, use NewVPNServerConfigurationsAssociatedWithVirtualWanServerTransport instead.
    43  type VPNServerConfigurationsAssociatedWithVirtualWanServerTransport struct {
    44  	srv       *VPNServerConfigurationsAssociatedWithVirtualWanServer
    45  	beginList *tracker[azfake.PollerResponder[armnetwork.VPNServerConfigurationsAssociatedWithVirtualWanClientListResponse]]
    46  }
    47  
    48  // Do implements the policy.Transporter interface for VPNServerConfigurationsAssociatedWithVirtualWanServerTransport.
    49  func (v *VPNServerConfigurationsAssociatedWithVirtualWanServerTransport) Do(req *http.Request) (*http.Response, error) {
    50  	rawMethod := req.Context().Value(runtime.CtxAPINameKey{})
    51  	method, ok := rawMethod.(string)
    52  	if !ok {
    53  		return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}
    54  	}
    55  
    56  	var resp *http.Response
    57  	var err error
    58  
    59  	switch method {
    60  	case "VPNServerConfigurationsAssociatedWithVirtualWanClient.BeginList":
    61  		resp, err = v.dispatchBeginList(req)
    62  	default:
    63  		err = fmt.Errorf("unhandled API %s", method)
    64  	}
    65  
    66  	if err != nil {
    67  		return nil, err
    68  	}
    69  
    70  	return resp, nil
    71  }
    72  
    73  func (v *VPNServerConfigurationsAssociatedWithVirtualWanServerTransport) dispatchBeginList(req *http.Request) (*http.Response, error) {
    74  	if v.srv.BeginList == nil {
    75  		return nil, &nonRetriableError{errors.New("fake for method BeginList not implemented")}
    76  	}
    77  	beginList := v.beginList.get(req)
    78  	if beginList == nil {
    79  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/virtualWans/(?P<virtualWANName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/vpnServerConfigurations`
    80  		regex := regexp.MustCompile(regexStr)
    81  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
    82  		if matches == nil || len(matches) < 3 {
    83  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
    84  		}
    85  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
    86  		if err != nil {
    87  			return nil, err
    88  		}
    89  		virtualWANNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("virtualWANName")])
    90  		if err != nil {
    91  			return nil, err
    92  		}
    93  		respr, errRespr := v.srv.BeginList(req.Context(), resourceGroupNameParam, virtualWANNameParam, nil)
    94  		if respErr := server.GetError(errRespr, req); respErr != nil {
    95  			return nil, respErr
    96  		}
    97  		beginList = &respr
    98  		v.beginList.add(req, beginList)
    99  	}
   100  
   101  	resp, err := server.PollerResponderNext(beginList, req)
   102  	if err != nil {
   103  		return nil, err
   104  	}
   105  
   106  	if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
   107  		v.beginList.remove(req)
   108  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
   109  	}
   110  	if !server.PollerResponderMore(beginList) {
   111  		v.beginList.remove(req)
   112  	}
   113  
   114  	return resp, nil
   115  }