github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/virtualhubbgpconnections_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  // VirtualHubBgpConnectionsServer is a fake server for instances of the armnetwork.VirtualHubBgpConnectionsClient type.
    26  type VirtualHubBgpConnectionsServer struct {
    27  	// NewListPager is the fake for method VirtualHubBgpConnectionsClient.NewListPager
    28  	// HTTP status codes to indicate success: http.StatusOK
    29  	NewListPager func(resourceGroupName string, virtualHubName string, options *armnetwork.VirtualHubBgpConnectionsClientListOptions) (resp azfake.PagerResponder[armnetwork.VirtualHubBgpConnectionsClientListResponse])
    30  
    31  	// BeginListAdvertisedRoutes is the fake for method VirtualHubBgpConnectionsClient.BeginListAdvertisedRoutes
    32  	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
    33  	BeginListAdvertisedRoutes func(ctx context.Context, resourceGroupName string, hubName string, connectionName string, options *armnetwork.VirtualHubBgpConnectionsClientBeginListAdvertisedRoutesOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionsClientListAdvertisedRoutesResponse], errResp azfake.ErrorResponder)
    34  
    35  	// BeginListLearnedRoutes is the fake for method VirtualHubBgpConnectionsClient.BeginListLearnedRoutes
    36  	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted
    37  	BeginListLearnedRoutes func(ctx context.Context, resourceGroupName string, hubName string, connectionName string, options *armnetwork.VirtualHubBgpConnectionsClientBeginListLearnedRoutesOptions) (resp azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionsClientListLearnedRoutesResponse], errResp azfake.ErrorResponder)
    38  }
    39  
    40  // NewVirtualHubBgpConnectionsServerTransport creates a new instance of VirtualHubBgpConnectionsServerTransport with the provided implementation.
    41  // The returned VirtualHubBgpConnectionsServerTransport instance is connected to an instance of armnetwork.VirtualHubBgpConnectionsClient via the
    42  // azcore.ClientOptions.Transporter field in the client's constructor parameters.
    43  func NewVirtualHubBgpConnectionsServerTransport(srv *VirtualHubBgpConnectionsServer) *VirtualHubBgpConnectionsServerTransport {
    44  	return &VirtualHubBgpConnectionsServerTransport{
    45  		srv:                       srv,
    46  		newListPager:              newTracker[azfake.PagerResponder[armnetwork.VirtualHubBgpConnectionsClientListResponse]](),
    47  		beginListAdvertisedRoutes: newTracker[azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionsClientListAdvertisedRoutesResponse]](),
    48  		beginListLearnedRoutes:    newTracker[azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionsClientListLearnedRoutesResponse]](),
    49  	}
    50  }
    51  
    52  // VirtualHubBgpConnectionsServerTransport connects instances of armnetwork.VirtualHubBgpConnectionsClient to instances of VirtualHubBgpConnectionsServer.
    53  // Don't use this type directly, use NewVirtualHubBgpConnectionsServerTransport instead.
    54  type VirtualHubBgpConnectionsServerTransport struct {
    55  	srv                       *VirtualHubBgpConnectionsServer
    56  	newListPager              *tracker[azfake.PagerResponder[armnetwork.VirtualHubBgpConnectionsClientListResponse]]
    57  	beginListAdvertisedRoutes *tracker[azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionsClientListAdvertisedRoutesResponse]]
    58  	beginListLearnedRoutes    *tracker[azfake.PollerResponder[armnetwork.VirtualHubBgpConnectionsClientListLearnedRoutesResponse]]
    59  }
    60  
    61  // Do implements the policy.Transporter interface for VirtualHubBgpConnectionsServerTransport.
    62  func (v *VirtualHubBgpConnectionsServerTransport) Do(req *http.Request) (*http.Response, error) {
    63  	rawMethod := req.Context().Value(runtime.CtxAPINameKey{})
    64  	method, ok := rawMethod.(string)
    65  	if !ok {
    66  		return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}
    67  	}
    68  
    69  	var resp *http.Response
    70  	var err error
    71  
    72  	switch method {
    73  	case "VirtualHubBgpConnectionsClient.NewListPager":
    74  		resp, err = v.dispatchNewListPager(req)
    75  	case "VirtualHubBgpConnectionsClient.BeginListAdvertisedRoutes":
    76  		resp, err = v.dispatchBeginListAdvertisedRoutes(req)
    77  	case "VirtualHubBgpConnectionsClient.BeginListLearnedRoutes":
    78  		resp, err = v.dispatchBeginListLearnedRoutes(req)
    79  	default:
    80  		err = fmt.Errorf("unhandled API %s", method)
    81  	}
    82  
    83  	if err != nil {
    84  		return nil, err
    85  	}
    86  
    87  	return resp, nil
    88  }
    89  
    90  func (v *VirtualHubBgpConnectionsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) {
    91  	if v.srv.NewListPager == nil {
    92  		return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")}
    93  	}
    94  	newListPager := v.newListPager.get(req)
    95  	if newListPager == nil {
    96  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/virtualHubs/(?P<virtualHubName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections`
    97  		regex := regexp.MustCompile(regexStr)
    98  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
    99  		if matches == nil || len(matches) < 3 {
   100  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   101  		}
   102  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   103  		if err != nil {
   104  			return nil, err
   105  		}
   106  		virtualHubNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("virtualHubName")])
   107  		if err != nil {
   108  			return nil, err
   109  		}
   110  		resp := v.srv.NewListPager(resourceGroupNameParam, virtualHubNameParam, nil)
   111  		newListPager = &resp
   112  		v.newListPager.add(req, newListPager)
   113  		server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.VirtualHubBgpConnectionsClientListResponse, createLink func() string) {
   114  			page.NextLink = to.Ptr(createLink())
   115  		})
   116  	}
   117  	resp, err := server.PagerResponderNext(newListPager, req)
   118  	if err != nil {
   119  		return nil, err
   120  	}
   121  	if !contains([]int{http.StatusOK}, resp.StatusCode) {
   122  		v.newListPager.remove(req)
   123  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
   124  	}
   125  	if !server.PagerResponderMore(newListPager) {
   126  		v.newListPager.remove(req)
   127  	}
   128  	return resp, nil
   129  }
   130  
   131  func (v *VirtualHubBgpConnectionsServerTransport) dispatchBeginListAdvertisedRoutes(req *http.Request) (*http.Response, error) {
   132  	if v.srv.BeginListAdvertisedRoutes == nil {
   133  		return nil, &nonRetriableError{errors.New("fake for method BeginListAdvertisedRoutes not implemented")}
   134  	}
   135  	beginListAdvertisedRoutes := v.beginListAdvertisedRoutes.get(req)
   136  	if beginListAdvertisedRoutes == nil {
   137  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/virtualHubs/(?P<hubName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections/(?P<connectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/advertisedRoutes`
   138  		regex := regexp.MustCompile(regexStr)
   139  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   140  		if matches == nil || len(matches) < 4 {
   141  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   142  		}
   143  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   144  		if err != nil {
   145  			return nil, err
   146  		}
   147  		hubNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("hubName")])
   148  		if err != nil {
   149  			return nil, err
   150  		}
   151  		connectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")])
   152  		if err != nil {
   153  			return nil, err
   154  		}
   155  		respr, errRespr := v.srv.BeginListAdvertisedRoutes(req.Context(), resourceGroupNameParam, hubNameParam, connectionNameParam, nil)
   156  		if respErr := server.GetError(errRespr, req); respErr != nil {
   157  			return nil, respErr
   158  		}
   159  		beginListAdvertisedRoutes = &respr
   160  		v.beginListAdvertisedRoutes.add(req, beginListAdvertisedRoutes)
   161  	}
   162  
   163  	resp, err := server.PollerResponderNext(beginListAdvertisedRoutes, req)
   164  	if err != nil {
   165  		return nil, err
   166  	}
   167  
   168  	if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
   169  		v.beginListAdvertisedRoutes.remove(req)
   170  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
   171  	}
   172  	if !server.PollerResponderMore(beginListAdvertisedRoutes) {
   173  		v.beginListAdvertisedRoutes.remove(req)
   174  	}
   175  
   176  	return resp, nil
   177  }
   178  
   179  func (v *VirtualHubBgpConnectionsServerTransport) dispatchBeginListLearnedRoutes(req *http.Request) (*http.Response, error) {
   180  	if v.srv.BeginListLearnedRoutes == nil {
   181  		return nil, &nonRetriableError{errors.New("fake for method BeginListLearnedRoutes not implemented")}
   182  	}
   183  	beginListLearnedRoutes := v.beginListLearnedRoutes.get(req)
   184  	if beginListLearnedRoutes == nil {
   185  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/virtualHubs/(?P<hubName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/bgpConnections/(?P<connectionName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/learnedRoutes`
   186  		regex := regexp.MustCompile(regexStr)
   187  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   188  		if matches == nil || len(matches) < 4 {
   189  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   190  		}
   191  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   192  		if err != nil {
   193  			return nil, err
   194  		}
   195  		hubNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("hubName")])
   196  		if err != nil {
   197  			return nil, err
   198  		}
   199  		connectionNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("connectionName")])
   200  		if err != nil {
   201  			return nil, err
   202  		}
   203  		respr, errRespr := v.srv.BeginListLearnedRoutes(req.Context(), resourceGroupNameParam, hubNameParam, connectionNameParam, nil)
   204  		if respErr := server.GetError(errRespr, req); respErr != nil {
   205  			return nil, respErr
   206  		}
   207  		beginListLearnedRoutes = &respr
   208  		v.beginListLearnedRoutes.add(req, beginListLearnedRoutes)
   209  	}
   210  
   211  	resp, err := server.PollerResponderNext(beginListLearnedRoutes, req)
   212  	if err != nil {
   213  		return nil, err
   214  	}
   215  
   216  	if !contains([]int{http.StatusOK, http.StatusAccepted}, resp.StatusCode) {
   217  		v.beginListLearnedRoutes.remove(req)
   218  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted", resp.StatusCode)}
   219  	}
   220  	if !server.PollerResponderMore(beginListLearnedRoutes) {
   221  		v.beginListLearnedRoutes.remove(req)
   222  	}
   223  
   224  	return resp, nil
   225  }