github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/fake/firewallpolicyrulecollectiongroups_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  // FirewallPolicyRuleCollectionGroupsServer is a fake server for instances of the armnetwork.FirewallPolicyRuleCollectionGroupsClient type.
    26  type FirewallPolicyRuleCollectionGroupsServer struct {
    27  	// BeginCreateOrUpdate is the fake for method FirewallPolicyRuleCollectionGroupsClient.BeginCreateOrUpdate
    28  	// HTTP status codes to indicate success: http.StatusOK, http.StatusCreated
    29  	BeginCreateOrUpdate func(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, parameters armnetwork.FirewallPolicyRuleCollectionGroup, options *armnetwork.FirewallPolicyRuleCollectionGroupsClientBeginCreateOrUpdateOptions) (resp azfake.PollerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder)
    30  
    31  	// BeginDelete is the fake for method FirewallPolicyRuleCollectionGroupsClient.BeginDelete
    32  	// HTTP status codes to indicate success: http.StatusOK, http.StatusAccepted, http.StatusNoContent
    33  	BeginDelete func(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, options *armnetwork.FirewallPolicyRuleCollectionGroupsClientBeginDeleteOptions) (resp azfake.PollerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientDeleteResponse], errResp azfake.ErrorResponder)
    34  
    35  	// Get is the fake for method FirewallPolicyRuleCollectionGroupsClient.Get
    36  	// HTTP status codes to indicate success: http.StatusOK
    37  	Get func(ctx context.Context, resourceGroupName string, firewallPolicyName string, ruleCollectionGroupName string, options *armnetwork.FirewallPolicyRuleCollectionGroupsClientGetOptions) (resp azfake.Responder[armnetwork.FirewallPolicyRuleCollectionGroupsClientGetResponse], errResp azfake.ErrorResponder)
    38  
    39  	// NewListPager is the fake for method FirewallPolicyRuleCollectionGroupsClient.NewListPager
    40  	// HTTP status codes to indicate success: http.StatusOK
    41  	NewListPager func(resourceGroupName string, firewallPolicyName string, options *armnetwork.FirewallPolicyRuleCollectionGroupsClientListOptions) (resp azfake.PagerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientListResponse])
    42  }
    43  
    44  // NewFirewallPolicyRuleCollectionGroupsServerTransport creates a new instance of FirewallPolicyRuleCollectionGroupsServerTransport with the provided implementation.
    45  // The returned FirewallPolicyRuleCollectionGroupsServerTransport instance is connected to an instance of armnetwork.FirewallPolicyRuleCollectionGroupsClient via the
    46  // azcore.ClientOptions.Transporter field in the client's constructor parameters.
    47  func NewFirewallPolicyRuleCollectionGroupsServerTransport(srv *FirewallPolicyRuleCollectionGroupsServer) *FirewallPolicyRuleCollectionGroupsServerTransport {
    48  	return &FirewallPolicyRuleCollectionGroupsServerTransport{
    49  		srv:                 srv,
    50  		beginCreateOrUpdate: newTracker[azfake.PollerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientCreateOrUpdateResponse]](),
    51  		beginDelete:         newTracker[azfake.PollerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientDeleteResponse]](),
    52  		newListPager:        newTracker[azfake.PagerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientListResponse]](),
    53  	}
    54  }
    55  
    56  // FirewallPolicyRuleCollectionGroupsServerTransport connects instances of armnetwork.FirewallPolicyRuleCollectionGroupsClient to instances of FirewallPolicyRuleCollectionGroupsServer.
    57  // Don't use this type directly, use NewFirewallPolicyRuleCollectionGroupsServerTransport instead.
    58  type FirewallPolicyRuleCollectionGroupsServerTransport struct {
    59  	srv                 *FirewallPolicyRuleCollectionGroupsServer
    60  	beginCreateOrUpdate *tracker[azfake.PollerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientCreateOrUpdateResponse]]
    61  	beginDelete         *tracker[azfake.PollerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientDeleteResponse]]
    62  	newListPager        *tracker[azfake.PagerResponder[armnetwork.FirewallPolicyRuleCollectionGroupsClientListResponse]]
    63  }
    64  
    65  // Do implements the policy.Transporter interface for FirewallPolicyRuleCollectionGroupsServerTransport.
    66  func (f *FirewallPolicyRuleCollectionGroupsServerTransport) Do(req *http.Request) (*http.Response, error) {
    67  	rawMethod := req.Context().Value(runtime.CtxAPINameKey{})
    68  	method, ok := rawMethod.(string)
    69  	if !ok {
    70  		return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}
    71  	}
    72  
    73  	var resp *http.Response
    74  	var err error
    75  
    76  	switch method {
    77  	case "FirewallPolicyRuleCollectionGroupsClient.BeginCreateOrUpdate":
    78  		resp, err = f.dispatchBeginCreateOrUpdate(req)
    79  	case "FirewallPolicyRuleCollectionGroupsClient.BeginDelete":
    80  		resp, err = f.dispatchBeginDelete(req)
    81  	case "FirewallPolicyRuleCollectionGroupsClient.Get":
    82  		resp, err = f.dispatchGet(req)
    83  	case "FirewallPolicyRuleCollectionGroupsClient.NewListPager":
    84  		resp, err = f.dispatchNewListPager(req)
    85  	default:
    86  		err = fmt.Errorf("unhandled API %s", method)
    87  	}
    88  
    89  	if err != nil {
    90  		return nil, err
    91  	}
    92  
    93  	return resp, nil
    94  }
    95  
    96  func (f *FirewallPolicyRuleCollectionGroupsServerTransport) dispatchBeginCreateOrUpdate(req *http.Request) (*http.Response, error) {
    97  	if f.srv.BeginCreateOrUpdate == nil {
    98  		return nil, &nonRetriableError{errors.New("fake for method BeginCreateOrUpdate not implemented")}
    99  	}
   100  	beginCreateOrUpdate := f.beginCreateOrUpdate.get(req)
   101  	if beginCreateOrUpdate == nil {
   102  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/firewallPolicies/(?P<firewallPolicyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroups/(?P<ruleCollectionGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
   103  		regex := regexp.MustCompile(regexStr)
   104  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   105  		if matches == nil || len(matches) < 4 {
   106  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   107  		}
   108  		body, err := server.UnmarshalRequestAsJSON[armnetwork.FirewallPolicyRuleCollectionGroup](req)
   109  		if err != nil {
   110  			return nil, err
   111  		}
   112  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   113  		if err != nil {
   114  			return nil, err
   115  		}
   116  		firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")])
   117  		if err != nil {
   118  			return nil, err
   119  		}
   120  		ruleCollectionGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionGroupName")])
   121  		if err != nil {
   122  			return nil, err
   123  		}
   124  		respr, errRespr := f.srv.BeginCreateOrUpdate(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, ruleCollectionGroupNameParam, body, nil)
   125  		if respErr := server.GetError(errRespr, req); respErr != nil {
   126  			return nil, respErr
   127  		}
   128  		beginCreateOrUpdate = &respr
   129  		f.beginCreateOrUpdate.add(req, beginCreateOrUpdate)
   130  	}
   131  
   132  	resp, err := server.PollerResponderNext(beginCreateOrUpdate, req)
   133  	if err != nil {
   134  		return nil, err
   135  	}
   136  
   137  	if !contains([]int{http.StatusOK, http.StatusCreated}, resp.StatusCode) {
   138  		f.beginCreateOrUpdate.remove(req)
   139  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusCreated", resp.StatusCode)}
   140  	}
   141  	if !server.PollerResponderMore(beginCreateOrUpdate) {
   142  		f.beginCreateOrUpdate.remove(req)
   143  	}
   144  
   145  	return resp, nil
   146  }
   147  
   148  func (f *FirewallPolicyRuleCollectionGroupsServerTransport) dispatchBeginDelete(req *http.Request) (*http.Response, error) {
   149  	if f.srv.BeginDelete == nil {
   150  		return nil, &nonRetriableError{errors.New("fake for method BeginDelete not implemented")}
   151  	}
   152  	beginDelete := f.beginDelete.get(req)
   153  	if beginDelete == nil {
   154  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/firewallPolicies/(?P<firewallPolicyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroups/(?P<ruleCollectionGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
   155  		regex := regexp.MustCompile(regexStr)
   156  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   157  		if matches == nil || len(matches) < 4 {
   158  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   159  		}
   160  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   161  		if err != nil {
   162  			return nil, err
   163  		}
   164  		firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")])
   165  		if err != nil {
   166  			return nil, err
   167  		}
   168  		ruleCollectionGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionGroupName")])
   169  		if err != nil {
   170  			return nil, err
   171  		}
   172  		respr, errRespr := f.srv.BeginDelete(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, ruleCollectionGroupNameParam, nil)
   173  		if respErr := server.GetError(errRespr, req); respErr != nil {
   174  			return nil, respErr
   175  		}
   176  		beginDelete = &respr
   177  		f.beginDelete.add(req, beginDelete)
   178  	}
   179  
   180  	resp, err := server.PollerResponderNext(beginDelete, req)
   181  	if err != nil {
   182  		return nil, err
   183  	}
   184  
   185  	if !contains([]int{http.StatusOK, http.StatusAccepted, http.StatusNoContent}, resp.StatusCode) {
   186  		f.beginDelete.remove(req)
   187  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK, http.StatusAccepted, http.StatusNoContent", resp.StatusCode)}
   188  	}
   189  	if !server.PollerResponderMore(beginDelete) {
   190  		f.beginDelete.remove(req)
   191  	}
   192  
   193  	return resp, nil
   194  }
   195  
   196  func (f *FirewallPolicyRuleCollectionGroupsServerTransport) dispatchGet(req *http.Request) (*http.Response, error) {
   197  	if f.srv.Get == nil {
   198  		return nil, &nonRetriableError{errors.New("fake for method Get not implemented")}
   199  	}
   200  	const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/firewallPolicies/(?P<firewallPolicyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroups/(?P<ruleCollectionGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)`
   201  	regex := regexp.MustCompile(regexStr)
   202  	matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   203  	if matches == nil || len(matches) < 4 {
   204  		return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   205  	}
   206  	resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   207  	if err != nil {
   208  		return nil, err
   209  	}
   210  	firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")])
   211  	if err != nil {
   212  		return nil, err
   213  	}
   214  	ruleCollectionGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("ruleCollectionGroupName")])
   215  	if err != nil {
   216  		return nil, err
   217  	}
   218  	respr, errRespr := f.srv.Get(req.Context(), resourceGroupNameParam, firewallPolicyNameParam, ruleCollectionGroupNameParam, nil)
   219  	if respErr := server.GetError(errRespr, req); respErr != nil {
   220  		return nil, respErr
   221  	}
   222  	respContent := server.GetResponseContent(respr)
   223  	if !contains([]int{http.StatusOK}, respContent.HTTPStatus) {
   224  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", respContent.HTTPStatus)}
   225  	}
   226  	resp, err := server.MarshalResponseAsJSON(respContent, server.GetResponse(respr).FirewallPolicyRuleCollectionGroup, req)
   227  	if err != nil {
   228  		return nil, err
   229  	}
   230  	return resp, nil
   231  }
   232  
   233  func (f *FirewallPolicyRuleCollectionGroupsServerTransport) dispatchNewListPager(req *http.Request) (*http.Response, error) {
   234  	if f.srv.NewListPager == nil {
   235  		return nil, &nonRetriableError{errors.New("fake for method NewListPager not implemented")}
   236  	}
   237  	newListPager := f.newListPager.get(req)
   238  	if newListPager == nil {
   239  		const regexStr = `/subscriptions/(?P<subscriptionId>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/resourceGroups/(?P<resourceGroupName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/providers/Microsoft\.Network/firewallPolicies/(?P<firewallPolicyName>[!#&$-;=?-\[\]_a-zA-Z0-9~%@]+)/ruleCollectionGroups`
   240  		regex := regexp.MustCompile(regexStr)
   241  		matches := regex.FindStringSubmatch(req.URL.EscapedPath())
   242  		if matches == nil || len(matches) < 3 {
   243  			return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)
   244  		}
   245  		resourceGroupNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("resourceGroupName")])
   246  		if err != nil {
   247  			return nil, err
   248  		}
   249  		firewallPolicyNameParam, err := url.PathUnescape(matches[regex.SubexpIndex("firewallPolicyName")])
   250  		if err != nil {
   251  			return nil, err
   252  		}
   253  		resp := f.srv.NewListPager(resourceGroupNameParam, firewallPolicyNameParam, nil)
   254  		newListPager = &resp
   255  		f.newListPager.add(req, newListPager)
   256  		server.PagerResponderInjectNextLinks(newListPager, req, func(page *armnetwork.FirewallPolicyRuleCollectionGroupsClientListResponse, createLink func() string) {
   257  			page.NextLink = to.Ptr(createLink())
   258  		})
   259  	}
   260  	resp, err := server.PagerResponderNext(newListPager, req)
   261  	if err != nil {
   262  		return nil, err
   263  	}
   264  	if !contains([]int{http.StatusOK}, resp.StatusCode) {
   265  		f.newListPager.remove(req)
   266  		return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are http.StatusOK", resp.StatusCode)}
   267  	}
   268  	if !server.PagerResponderMore(newListPager) {
   269  		f.newListPager.remove(req)
   270  	}
   271  	return resp, nil
   272  }