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