github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/ddosprotectionplan_live_test.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  
     7  package armnetwork_test
     8  
     9  import (
    10  	"context"
    11  	"fmt"
    12  	"testing"
    13  
    14  	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
    15  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
    16  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
    17  	"github.com/Azure/azure-sdk-for-go/sdk/internal/recording"
    18  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v3/testutil"
    19  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"
    20  	"github.com/stretchr/testify/suite"
    21  )
    22  
    23  type DdosProtectionPlanTestSuite struct {
    24  	suite.Suite
    25  
    26  	ctx                    context.Context
    27  	cred                   azcore.TokenCredential
    28  	options                *arm.ClientOptions
    29  	ddosProtectionPlanName string
    30  	location               string
    31  	resourceGroupName      string
    32  	subscriptionId         string
    33  }
    34  
    35  func (testsuite *DdosProtectionPlanTestSuite) SetupSuite() {
    36  	testutil.StartRecording(testsuite.T(), pathToPackage)
    37  
    38  	testsuite.ctx = context.Background()
    39  	testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T())
    40  	testsuite.ddosProtectionPlanName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "ddosprotec", 16, false)
    41  	testsuite.location = recording.GetEnvVariable("LOCATION", "westus")
    42  	testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup")
    43  	testsuite.subscriptionId = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
    44  	resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location)
    45  	testsuite.Require().NoError(err)
    46  	testsuite.resourceGroupName = *resourceGroup.Name
    47  }
    48  
    49  func (testsuite *DdosProtectionPlanTestSuite) TearDownSuite() {
    50  	_, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName)
    51  	testsuite.Require().NoError(err)
    52  	testutil.StopRecording(testsuite.T())
    53  }
    54  
    55  func TestDdosProtectionPlanTestSuite(t *testing.T) {
    56  	suite.Run(t, new(DdosProtectionPlanTestSuite))
    57  }
    58  
    59  // Microsoft.Network/ddosProtectionPlans/{ddosProtectionPlanName}
    60  func (testsuite *DdosProtectionPlanTestSuite) TestDdosProtectionPlans() {
    61  	var err error
    62  	// From step DdosProtectionPlans_CreateOrUpdate
    63  	fmt.Println("Call operation: DdosProtectionPlans_CreateOrUpdate")
    64  	ddosProtectionPlansClient, err := armnetwork.NewDdosProtectionPlansClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
    65  	testsuite.Require().NoError(err)
    66  	ddosProtectionPlansClientCreateOrUpdateResponsePoller, err := ddosProtectionPlansClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.ddosProtectionPlanName, armnetwork.DdosProtectionPlan{
    67  		Location:   to.Ptr(testsuite.location),
    68  		Properties: &armnetwork.DdosProtectionPlanPropertiesFormat{},
    69  	}, nil)
    70  	testsuite.Require().NoError(err)
    71  	_, err = testutil.PollForTest(testsuite.ctx, ddosProtectionPlansClientCreateOrUpdateResponsePoller)
    72  	testsuite.Require().NoError(err)
    73  
    74  	// From step DdosProtectionPlans_List
    75  	fmt.Println("Call operation: DdosProtectionPlans_List")
    76  	ddosProtectionPlansClientNewListPager := ddosProtectionPlansClient.NewListPager(nil)
    77  	for ddosProtectionPlansClientNewListPager.More() {
    78  		_, err := ddosProtectionPlansClientNewListPager.NextPage(testsuite.ctx)
    79  		testsuite.Require().NoError(err)
    80  		break
    81  	}
    82  
    83  	// From step DdosProtectionPlans_ListByResourceGroup
    84  	fmt.Println("Call operation: DdosProtectionPlans_ListByResourceGroup")
    85  	ddosProtectionPlansClientNewListByResourceGroupPager := ddosProtectionPlansClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil)
    86  	for ddosProtectionPlansClientNewListByResourceGroupPager.More() {
    87  		_, err := ddosProtectionPlansClientNewListByResourceGroupPager.NextPage(testsuite.ctx)
    88  		testsuite.Require().NoError(err)
    89  		break
    90  	}
    91  
    92  	// From step DdosProtectionPlans_Get
    93  	fmt.Println("Call operation: DdosProtectionPlans_Get")
    94  	_, err = ddosProtectionPlansClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.ddosProtectionPlanName, nil)
    95  	testsuite.Require().NoError(err)
    96  
    97  	// From step DdosProtectionPlans_UpdateTags
    98  	fmt.Println("Call operation: DdosProtectionPlans_UpdateTags")
    99  	_, err = ddosProtectionPlansClient.UpdateTags(testsuite.ctx, testsuite.resourceGroupName, testsuite.ddosProtectionPlanName, armnetwork.TagsObject{
   100  		Tags: map[string]*string{
   101  			"tag1": to.Ptr("value1"),
   102  			"tag2": to.Ptr("value2"),
   103  		},
   104  	}, nil)
   105  	testsuite.Require().NoError(err)
   106  
   107  	// From step DdosProtectionPlans_Delete
   108  	fmt.Println("Call operation: DdosProtectionPlans_Delete")
   109  	ddosProtectionPlansClientDeleteResponsePoller, err := ddosProtectionPlansClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.ddosProtectionPlanName, nil)
   110  	testsuite.Require().NoError(err)
   111  	_, err = testutil.PollForTest(testsuite.ctx, ddosProtectionPlansClientDeleteResponsePoller)
   112  	testsuite.Require().NoError(err)
   113  }