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