github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/bastionhost_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 BastionHostTestSuite struct { 24 suite.Suite 25 26 ctx context.Context 27 cred azcore.TokenCredential 28 options *arm.ClientOptions 29 bastionHostName string 30 publicIpAddressId string 31 subnetId string 32 location string 33 resourceGroupName string 34 subscriptionId string 35 } 36 37 func (testsuite *BastionHostTestSuite) SetupSuite() { 38 testutil.StartRecording(testsuite.T(), pathToPackage) 39 40 testsuite.ctx = context.Background() 41 testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) 42 testsuite.bastionHostName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "bastionhos", 16, false) 43 testsuite.location = recording.GetEnvVariable("LOCATION", "westus") 44 testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") 45 testsuite.subscriptionId = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") 46 resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) 47 testsuite.Require().NoError(err) 48 testsuite.resourceGroupName = *resourceGroup.Name 49 testsuite.Prepare() 50 } 51 52 func (testsuite *BastionHostTestSuite) TearDownSuite() { 53 _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) 54 testsuite.Require().NoError(err) 55 testutil.StopRecording(testsuite.T()) 56 } 57 58 func TestBastionHostTestSuite(t *testing.T) { 59 suite.Run(t, new(BastionHostTestSuite)) 60 } 61 62 func (testsuite *BastionHostTestSuite) Prepare() { 63 var err error 64 // From step VirtualNetworks_CreateOrUpdate 65 fmt.Println("Call operation: VirtualNetworks_CreateOrUpdate") 66 virtualNetworksClient, err := armnetwork.NewVirtualNetworksClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) 67 testsuite.Require().NoError(err) 68 virtualNetworksClientCreateOrUpdateResponsePoller, err := virtualNetworksClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, "test-vnet", armnetwork.VirtualNetwork{ 69 Location: to.Ptr(testsuite.location), 70 Properties: &armnetwork.VirtualNetworkPropertiesFormat{ 71 AddressSpace: &armnetwork.AddressSpace{ 72 AddressPrefixes: []*string{ 73 to.Ptr("10.0.0.0/16")}, 74 }, 75 Subnets: []*armnetwork.Subnet{ 76 { 77 Name: to.Ptr("AzureBastionSubnet"), 78 Properties: &armnetwork.SubnetPropertiesFormat{ 79 AddressPrefix: to.Ptr("10.0.0.0/24"), 80 }, 81 }}, 82 }, 83 }, nil) 84 testsuite.Require().NoError(err) 85 var virtualNetworksClientCreateOrUpdateResponse *armnetwork.VirtualNetworksClientCreateOrUpdateResponse 86 virtualNetworksClientCreateOrUpdateResponse, err = testutil.PollForTest(testsuite.ctx, virtualNetworksClientCreateOrUpdateResponsePoller) 87 testsuite.Require().NoError(err) 88 testsuite.subnetId = *virtualNetworksClientCreateOrUpdateResponse.Properties.Subnets[0].ID 89 90 // From step PublicIPAddresses_CreateOrUpdate 91 fmt.Println("Call operation: PublicIPAddresses_CreateOrUpdate") 92 publicIPAddressesClient, err := armnetwork.NewPublicIPAddressesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) 93 testsuite.Require().NoError(err) 94 publicIPAddressesClientCreateOrUpdateResponsePoller, err := publicIPAddressesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, "test-ip", armnetwork.PublicIPAddress{ 95 Location: to.Ptr(testsuite.location), 96 Properties: &armnetwork.PublicIPAddressPropertiesFormat{ 97 IdleTimeoutInMinutes: to.Ptr[int32](10), 98 PublicIPAddressVersion: to.Ptr(armnetwork.IPVersionIPv4), 99 PublicIPAllocationMethod: to.Ptr(armnetwork.IPAllocationMethodStatic), 100 }, 101 SKU: &armnetwork.PublicIPAddressSKU{ 102 Name: to.Ptr(armnetwork.PublicIPAddressSKUNameStandard), 103 Tier: to.Ptr(armnetwork.PublicIPAddressSKUTierRegional), 104 }, 105 }, nil) 106 testsuite.Require().NoError(err) 107 var publicIPAddressesClientCreateOrUpdateResponse *armnetwork.PublicIPAddressesClientCreateOrUpdateResponse 108 publicIPAddressesClientCreateOrUpdateResponse, err = testutil.PollForTest(testsuite.ctx, publicIPAddressesClientCreateOrUpdateResponsePoller) 109 testsuite.Require().NoError(err) 110 testsuite.publicIpAddressId = *publicIPAddressesClientCreateOrUpdateResponse.ID 111 } 112 113 // Microsoft.Network/bastionHosts/{bastionHostName} 114 func (testsuite *BastionHostTestSuite) TestBastionHosts() { 115 var err error 116 // From step BastionHosts_CreateOrUpdate 117 fmt.Println("Call operation: BastionHosts_CreateOrUpdate") 118 bastionHostsClient, err := armnetwork.NewBastionHostsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) 119 testsuite.Require().NoError(err) 120 bastionHostsClientCreateOrUpdateResponsePoller, err := bastionHostsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.bastionHostName, armnetwork.BastionHost{ 121 Location: to.Ptr(testsuite.location), 122 Properties: &armnetwork.BastionHostPropertiesFormat{ 123 IPConfigurations: []*armnetwork.BastionHostIPConfiguration{ 124 { 125 Name: to.Ptr("bastionHostIpConfiguration"), 126 Properties: &armnetwork.BastionHostIPConfigurationPropertiesFormat{ 127 PublicIPAddress: &armnetwork.SubResource{ 128 ID: to.Ptr(testsuite.publicIpAddressId), 129 }, 130 Subnet: &armnetwork.SubResource{ 131 ID: to.Ptr(testsuite.subnetId), 132 }, 133 }, 134 }}, 135 }, 136 }, nil) 137 testsuite.Require().NoError(err) 138 _, err = testutil.PollForTest(testsuite.ctx, bastionHostsClientCreateOrUpdateResponsePoller) 139 testsuite.Require().NoError(err) 140 141 // From step BastionHosts_List 142 fmt.Println("Call operation: BastionHosts_List") 143 bastionHostsClientNewListPager := bastionHostsClient.NewListPager(nil) 144 for bastionHostsClientNewListPager.More() { 145 _, err := bastionHostsClientNewListPager.NextPage(testsuite.ctx) 146 testsuite.Require().NoError(err) 147 break 148 } 149 150 // From step BastionHosts_ListByResourceGroup 151 fmt.Println("Call operation: BastionHosts_ListByResourceGroup") 152 bastionHostsClientNewListByResourceGroupPager := bastionHostsClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) 153 for bastionHostsClientNewListByResourceGroupPager.More() { 154 _, err := bastionHostsClientNewListByResourceGroupPager.NextPage(testsuite.ctx) 155 testsuite.Require().NoError(err) 156 break 157 } 158 159 // From step BastionHosts_Get 160 fmt.Println("Call operation: BastionHosts_Get") 161 _, err = bastionHostsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.bastionHostName, nil) 162 testsuite.Require().NoError(err) 163 164 // From step BastionHosts_UpdateTags 165 fmt.Println("Call operation: BastionHosts_UpdateTags") 166 bastionHostsClientUpdateTagsResponsePoller, err := bastionHostsClient.BeginUpdateTags(testsuite.ctx, testsuite.resourceGroupName, testsuite.bastionHostName, armnetwork.TagsObject{ 167 Tags: map[string]*string{ 168 "tag1": to.Ptr("value1"), 169 "tag2": to.Ptr("value2"), 170 }, 171 }, nil) 172 testsuite.Require().NoError(err) 173 _, err = testutil.PollForTest(testsuite.ctx, bastionHostsClientUpdateTagsResponsePoller) 174 testsuite.Require().NoError(err) 175 176 // From step BastionHosts_Delete 177 fmt.Println("Call operation: BastionHosts_Delete") 178 bastionHostsClientDeleteResponsePoller, err := bastionHostsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.bastionHostName, nil) 179 testsuite.Require().NoError(err) 180 _, err = testutil.PollForTest(testsuite.ctx, bastionHostsClientDeleteResponsePoller) 181 testsuite.Require().NoError(err) 182 }