github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/publicipaddress_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 PublicIpAddressTestSuite struct {
    24  	suite.Suite
    25  
    26  	ctx                 context.Context
    27  	cred                azcore.TokenCredential
    28  	options             *arm.ClientOptions
    29  	publicIpAddressName string
    30  	location            string
    31  	resourceGroupName   string
    32  	subscriptionId      string
    33  }
    34  
    35  func (testsuite *PublicIpAddressTestSuite) SetupSuite() {
    36  	testutil.StartRecording(testsuite.T(), pathToPackage)
    37  
    38  	testsuite.ctx = context.Background()
    39  	testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T())
    40  	testsuite.publicIpAddressName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "publicipad", 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 *PublicIpAddressTestSuite) 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 TestPublicIpAddressTestSuite(t *testing.T) {
    56  	suite.Run(t, new(PublicIpAddressTestSuite))
    57  }
    58  
    59  // Microsoft.Network/publicIPAddresses/{publicIpAddressName}
    60  func (testsuite *PublicIpAddressTestSuite) TestPublicIpAddresses() {
    61  	var err error
    62  	// From step PublicIPAddresses_CreateOrUpdate
    63  	fmt.Println("Call operation: PublicIPAddresses_CreateOrUpdate")
    64  	publicIPAddressesClient, err := armnetwork.NewPublicIPAddressesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
    65  	testsuite.Require().NoError(err)
    66  	publicIPAddressesClientCreateOrUpdateResponsePoller, err := publicIPAddressesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.publicIpAddressName, armnetwork.PublicIPAddress{
    67  		Location: to.Ptr(testsuite.location),
    68  	}, nil)
    69  	testsuite.Require().NoError(err)
    70  	_, err = testutil.PollForTest(testsuite.ctx, publicIPAddressesClientCreateOrUpdateResponsePoller)
    71  	testsuite.Require().NoError(err)
    72  
    73  	// From step PublicIPAddresses_ListAll
    74  	fmt.Println("Call operation: PublicIPAddresses_ListAll")
    75  	publicIPAddressesClientNewListAllPager := publicIPAddressesClient.NewListAllPager(nil)
    76  	for publicIPAddressesClientNewListAllPager.More() {
    77  		_, err := publicIPAddressesClientNewListAllPager.NextPage(testsuite.ctx)
    78  		testsuite.Require().NoError(err)
    79  		break
    80  	}
    81  
    82  	// From step PublicIPAddresses_List
    83  	fmt.Println("Call operation: PublicIPAddresses_List")
    84  	publicIPAddressesClientNewListPager := publicIPAddressesClient.NewListPager(testsuite.resourceGroupName, nil)
    85  	for publicIPAddressesClientNewListPager.More() {
    86  		_, err := publicIPAddressesClientNewListPager.NextPage(testsuite.ctx)
    87  		testsuite.Require().NoError(err)
    88  		break
    89  	}
    90  
    91  	// From step PublicIPAddresses_Get
    92  	fmt.Println("Call operation: PublicIPAddresses_Get")
    93  	_, err = publicIPAddressesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.publicIpAddressName, &armnetwork.PublicIPAddressesClientGetOptions{Expand: nil})
    94  	testsuite.Require().NoError(err)
    95  
    96  	// From step PublicIPAddresses_UpdateTags
    97  	fmt.Println("Call operation: PublicIPAddresses_UpdateTags")
    98  	_, err = publicIPAddressesClient.UpdateTags(testsuite.ctx, testsuite.resourceGroupName, testsuite.publicIpAddressName, armnetwork.TagsObject{
    99  		Tags: map[string]*string{
   100  			"tag1": to.Ptr("value1"),
   101  			"tag2": to.Ptr("value2"),
   102  		},
   103  	}, nil)
   104  	testsuite.Require().NoError(err)
   105  
   106  	// From step PublicIPAddresses_Delete
   107  	fmt.Println("Call operation: PublicIPAddresses_Delete")
   108  	publicIPAddressesClientDeleteResponsePoller, err := publicIPAddressesClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.publicIpAddressName, nil)
   109  	testsuite.Require().NoError(err)
   110  	_, err = testutil.PollForTest(testsuite.ctx, publicIPAddressesClientDeleteResponsePoller)
   111  	testsuite.Require().NoError(err)
   112  }