github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/publicipprefix_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 PublicIpPrefixTestSuite struct { 24 suite.Suite 25 26 ctx context.Context 27 cred azcore.TokenCredential 28 options *arm.ClientOptions 29 publicIpPrefixName string 30 location string 31 resourceGroupName string 32 subscriptionId string 33 } 34 35 func (testsuite *PublicIpPrefixTestSuite) SetupSuite() { 36 testutil.StartRecording(testsuite.T(), pathToPackage) 37 38 testsuite.ctx = context.Background() 39 testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) 40 testsuite.publicIpPrefixName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "publicippr", 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 *PublicIpPrefixTestSuite) 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 TestPublicIpPrefixTestSuite(t *testing.T) { 56 suite.Run(t, new(PublicIpPrefixTestSuite)) 57 } 58 59 // Microsoft.Network/publicIPPrefixes/{publicIpPrefixName} 60 func (testsuite *PublicIpPrefixTestSuite) TestPublicIpPrefixes() { 61 var err error 62 // From step PublicIPPrefixes_CreateOrUpdate 63 fmt.Println("Call operation: PublicIPPrefixes_CreateOrUpdate") 64 publicIPPrefixesClient, err := armnetwork.NewPublicIPPrefixesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) 65 testsuite.Require().NoError(err) 66 publicIPPrefixesClientCreateOrUpdateResponsePoller, err := publicIPPrefixesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.publicIpPrefixName, armnetwork.PublicIPPrefix{ 67 Location: to.Ptr(testsuite.location), 68 Properties: &armnetwork.PublicIPPrefixPropertiesFormat{ 69 PrefixLength: to.Ptr[int32](30), 70 }, 71 SKU: &armnetwork.PublicIPPrefixSKU{ 72 Name: to.Ptr(armnetwork.PublicIPPrefixSKUNameStandard), 73 }, 74 }, nil) 75 testsuite.Require().NoError(err) 76 _, err = testutil.PollForTest(testsuite.ctx, publicIPPrefixesClientCreateOrUpdateResponsePoller) 77 testsuite.Require().NoError(err) 78 79 // From step PublicIPPrefixes_ListAll 80 fmt.Println("Call operation: PublicIPPrefixes_ListAll") 81 publicIPPrefixesClientNewListAllPager := publicIPPrefixesClient.NewListAllPager(nil) 82 for publicIPPrefixesClientNewListAllPager.More() { 83 _, err := publicIPPrefixesClientNewListAllPager.NextPage(testsuite.ctx) 84 testsuite.Require().NoError(err) 85 break 86 } 87 88 // From step PublicIPPrefixes_List 89 fmt.Println("Call operation: PublicIPPrefixes_List") 90 publicIPPrefixesClientNewListPager := publicIPPrefixesClient.NewListPager(testsuite.resourceGroupName, nil) 91 for publicIPPrefixesClientNewListPager.More() { 92 _, err := publicIPPrefixesClientNewListPager.NextPage(testsuite.ctx) 93 testsuite.Require().NoError(err) 94 break 95 } 96 97 // From step PublicIPPrefixes_Get 98 fmt.Println("Call operation: PublicIPPrefixes_Get") 99 _, err = publicIPPrefixesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.publicIpPrefixName, &armnetwork.PublicIPPrefixesClientGetOptions{Expand: nil}) 100 testsuite.Require().NoError(err) 101 102 // From step PublicIPPrefixes_UpdateTags 103 fmt.Println("Call operation: PublicIPPrefixes_UpdateTags") 104 _, err = publicIPPrefixesClient.UpdateTags(testsuite.ctx, testsuite.resourceGroupName, testsuite.publicIpPrefixName, armnetwork.TagsObject{ 105 Tags: map[string]*string{ 106 "tag1": to.Ptr("value1"), 107 "tag2": to.Ptr("value2"), 108 }, 109 }, nil) 110 testsuite.Require().NoError(err) 111 112 // From step PublicIPPrefixes_Delete 113 fmt.Println("Call operation: PublicIPPrefixes_Delete") 114 publicIPPrefixesClientDeleteResponsePoller, err := publicIPPrefixesClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.publicIpPrefixName, nil) 115 testsuite.Require().NoError(err) 116 _, err = testutil.PollForTest(testsuite.ctx, publicIPPrefixesClientDeleteResponsePoller) 117 testsuite.Require().NoError(err) 118 }