github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/customipprefix_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 CustomIpPrefixTestSuite struct { 24 suite.Suite 25 26 ctx context.Context 27 cred azcore.TokenCredential 28 options *arm.ClientOptions 29 customIpPrefixName string 30 location string 31 resourceGroupName string 32 subscriptionId string 33 } 34 35 func (testsuite *CustomIpPrefixTestSuite) SetupSuite() { 36 testutil.StartRecording(testsuite.T(), pathToPackage) 37 38 testsuite.ctx = context.Background() 39 testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) 40 testsuite.customIpPrefixName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "customippr", 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 *CustomIpPrefixTestSuite) 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 TestCustomIpPrefixTestSuite(t *testing.T) { 56 suite.Run(t, new(CustomIpPrefixTestSuite)) 57 } 58 59 // Microsoft.Network/customIpPrefixes/{customIpPrefixName} 60 func (testsuite *CustomIpPrefixTestSuite) TestCustomIpPrefixes() { 61 var err error 62 // From step CustomIPPrefixes_CreateOrUpdate 63 fmt.Println("Call operation: CustomIPPrefixes_CreateOrUpdate") 64 customIPPrefixesClient, err := armnetwork.NewCustomIPPrefixesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) 65 testsuite.Require().NoError(err) 66 customIPPrefixesClientCreateOrUpdateResponsePoller, err := customIPPrefixesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.customIpPrefixName, armnetwork.CustomIPPrefix{ 67 Location: to.Ptr(testsuite.location), 68 Properties: &armnetwork.CustomIPPrefixPropertiesFormat{ 69 Cidr: to.Ptr("0.0.0.0/24"), 70 }, 71 }, nil) 72 testsuite.Require().NoError(err) 73 _, err = testutil.PollForTest(testsuite.ctx, customIPPrefixesClientCreateOrUpdateResponsePoller) 74 testsuite.Require().NoError(err) 75 76 // From step CustomIPPrefixes_ListAll 77 fmt.Println("Call operation: CustomIPPrefixes_ListAll") 78 customIPPrefixesClientNewListAllPager := customIPPrefixesClient.NewListAllPager(nil) 79 for customIPPrefixesClientNewListAllPager.More() { 80 _, err := customIPPrefixesClientNewListAllPager.NextPage(testsuite.ctx) 81 testsuite.Require().NoError(err) 82 break 83 } 84 85 // From step CustomIPPrefixes_List 86 fmt.Println("Call operation: CustomIPPrefixes_List") 87 customIPPrefixesClientNewListPager := customIPPrefixesClient.NewListPager(testsuite.resourceGroupName, nil) 88 for customIPPrefixesClientNewListPager.More() { 89 _, err := customIPPrefixesClientNewListPager.NextPage(testsuite.ctx) 90 testsuite.Require().NoError(err) 91 break 92 } 93 94 // From step CustomIPPrefixes_Get 95 fmt.Println("Call operation: CustomIPPrefixes_Get") 96 _, err = customIPPrefixesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.customIpPrefixName, &armnetwork.CustomIPPrefixesClientGetOptions{Expand: nil}) 97 testsuite.Require().NoError(err) 98 99 // From step CustomIPPrefixes_UpdateTags 100 fmt.Println("Call operation: CustomIPPrefixes_UpdateTags") 101 _, err = customIPPrefixesClient.UpdateTags(testsuite.ctx, testsuite.resourceGroupName, testsuite.customIpPrefixName, armnetwork.TagsObject{ 102 Tags: map[string]*string{ 103 "tag1": to.Ptr("value1"), 104 "tag2": to.Ptr("value2"), 105 }, 106 }, nil) 107 testsuite.Require().NoError(err) 108 }