github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/interfaceipconfigurations_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  // InterfaceIPConfigurationsServer is a fake server for instances of the armnetwork.InterfaceIPConfigurationsClient type.
    26  type InterfaceIPConfigurationsServer struct {
    27  	// Get is the fake for method InterfaceIPConfigurationsClient.Get
    28  	// HTTP status codes to indicate success: http.StatusOK
    29  	Get func(ctx context.Context, resourceGroupName string, networkInterfaceName string, ipConfigurationName string, options *armnetwork.InterfaceIPConfigurationsClientGetOptions) (resp azfake.Responder[armnetwork.InterfaceIPConfigurationsClientGetResponse], errResp azfake.ErrorResponder)
    30  
    31  	// NewListPager is the fake for method InterfaceIPConfigurationsClient.NewListPager
    32  	// HTTP status codes to indicate success: http.StatusOK
    33  	NewListPager func(resourceGroupName string, networkInterfaceName string, options *armnetwork.InterfaceIPConfigurationsClientListOptions) (resp azfake.PagerResponder[armnetwork.InterfaceIPConfigurationsClientListResponse])
    34  }
    35  
    36  // NewInterfaceIPConfigurationsServerTransport creates a new instance of InterfaceIPConfigurationsServerTransport with the provided implementation.
    37  // The returned InterfaceIPConfigurationsServerTransport instance is connected to an instance of armnetwork.InterfaceIPConfigurationsClient via the
    38  // azcore.ClientOptions.Transporter field in the client's constructor parameters.
    39  func NewInterfaceIPConfigurationsServerTransport(srv *InterfaceIPConfigurationsServer) *InterfaceIPConfigurationsServerTransport {
    40  	return &InterfaceIPConfigurationsServerTransport{
    41  		srv:          srv,
    42  		newListPager: newTracker[azfake.PagerResponder[armnetwork.InterfaceIPConfigurationsClientListResponse]](),
    43  	}
    44  }
    45  
    46  // InterfaceIPConfigurationsServerTransport connects instances of armnetwork.InterfaceIPConfigurationsClient to instances of InterfaceIPConfigurationsServer.
    47  // Don't use this type directly, use NewInterfaceIPConfigurationsServerTransport instead.
    48  type InterfaceIPConfigurationsServerTransport struct {
    49  	srv          *InterfaceIPConfigurationsServer
    50  	newListPager *tracker[azfake.PagerResponder[armnetwork.InterfaceIPConfigurationsClientListResponse]]
    51  }
    52  
    53  // Do implements the policy.Transporter interface for InterfaceIPConfigurationsServerTransport.
    54  func (i *InterfaceIPConfigurationsServerTransport) Do(req *http.Request) (*http.Response, error) {
    55  	rawMethod := req.Context().Value(runtime.CtxAPINameKey{})
    56  	method, ok := rawMethod.(string)
    57  	if !ok {
    58  		return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}
    59  	}
    60  
    61  	var resp *http.Response
    62  	var err error
    63  
    64  	switch method {
    65  	case "InterfaceIPConfigurationsClient.Get":
    66  		resp, err = i.dispatchGet(req)
    67  	case "InterfaceIPConfigurationsClient.NewListPager":
    68  		resp, err = i.dispatchNewListPager(req)
    69  	default:
    70  		err = fmt.Errorf("unhandled API %s", method)
    71  	}
    72  
    73  	if err != nil {
    74  		return nil, err
    75  	}
    76  
    77  	return resp, nil
    78  }
    79  
    80  func (i *InterfaceIPConfigurationsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
    81  	if i.srv.Get == nil {
    82  		return nil, &nonRetriableError{errors.New("fake for method Get not implemented")}
    83  	}
    84  	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkInterfaces/(?P<networkInterfaceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipConfigurations/(?P<ipConfigurationName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
    85  	regex := regexp.MustCompile(regexStr)
    86  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
    87  	if matches == nil || len(matches) < 4 {
    88  		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
    89  	}
    90  	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
    91  	if err != nil {
    92  		return nil, err
    93  	}
    94  	networkInterfaceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")])
    95  	if err != nil {
    96  		return nil, err
    97  	}
    98  	ipConfigurationNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ipConfigurationName")])
    99  	if err != nil {
   100  		return nil, err
   101  	}
   102  	respr, errRespr := i.srv.Get(req.Context(), resourceGroupNameParam, networkInterfaceNameParam, ipConfigurationNameParam, nil)
   103  	if respErr := server.GetError(errRespr, req); respErr != nil {
   104  		return nil, respErr
   105  	}
   106  	respContent := server.GetResponseContent(respr)
   107  	if !contains([]int{http.StatusOK}, respContent.HTTPStatus) {
   108  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)}
   109  	}
   110  	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).InterfaceIPConfiguration, req)
   111  	if err != nil {
   112  		return nil, err
   113  	}
   114  	return resp, nil
   115  }
   116  
   117  func (i *InterfaceIPConfigurationsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) {
   118  	if i.srv.NewListPager == nil {
   119  		return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")}
   120  	}
   121  	newListPager := i.newListPager.get(req)
   122  	if newListPager == nil {
   123  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/networkInterfaces/(?P<networkInterfaceName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ipConfigurations`
   124  		regex := regexp.MustCompile(regexStr)
   125  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   126  		if matches == nil || len(matches) < 3 {
   127  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   128  		}
   129  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   130  		if err != nil {
   131  			return nil, err
   132  		}
   133  		networkInterfaceNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("networkInterfaceName")])
   134  		if err != nil {
   135  			return nil, err
   136  		}
   137  		resp := i.srv.NewListPager(resourceGroupNameParam, networkInterfaceNameParam, nil)
   138  		newListPager = &resp
   139  		i.newListPager.add(req, newListPager)
   140  		server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.InterfaceIPConfigurationsClientListResponse, createLink func() string) {
   141  			page.NextLink = to.Ptr(createLink())
   142  		})
   143  	}
   144  	resp, err := server.PagerResponderNext(newListPager, req)
   145  	if err != nil {
   146  		return nil, err
   147  	}
   148  	if !contains([]int{http.StatusOK}, resp.StatusCode) {
   149  		i.newListPager.remove(req)
   150  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
   151  	}
   152  	if !server.PagerResponderMore(newListPager) {
   153  		i.newListPager.remove(req)
   154  	}
   155  	return resp, nil
   156  }