From 5fa7df4852a100f4a7502d5064ae54b0aceb8260 Mon Sep 17 00:00:00 2001 From: Peng Jiahui <46921893+Alancere@users.noreply.github.com> Date: Thu, 4 May 2023 15:13:26 +0800 Subject: [PATCH] add sdk/resourcemanager/compute/armcompute live test (#20048) * add sdk/resourcemanager/compute/armcompute live test * skus filter * fix subscriptionId default value * fix * gofmt * update recording --- .../compute/armcompute/assets.json | 2 +- .../armcompute/availabilityset_live_test.go | 117 +++++ .../availabilitysets_client_live_test.go | 120 ----- .../capacityreservation_live_test.go | 122 +++++ .../armcompute/computerpcommon_live_test.go | 100 ++++ .../armcompute/dedicatedhost_live_test.go | 174 ++++++ .../compute/armcompute/disk_live_test.go | 137 +++++ .../armcompute/diskaccess_live_test.go | 129 +++++ .../compute/armcompute/gallery_live_test.go | 265 ++++++++++ sdk/resourcemanager/compute/armcompute/go.mod | 3 +- sdk/resourcemanager/compute/armcompute/go.sum | 7 +- .../proximityplacementgroup_live_test.go | 118 +++++ .../armcompute/restorepoint_live_test.go | 291 ++++++++++ .../armcompute/runcommand_live_test.go | 495 ++++++++++++++++++ .../compute/armcompute/skus_live_test.go | 73 +++ .../compute/armcompute/snapshot_live_test.go | 141 +++++ .../armcompute/sshpublickey_live_test.go | 113 ++++ .../armcompute/virtualmachine_live_test.go | 348 ++++++++++++ .../virtualmachineextensionimage_live_test.go | 82 +++ .../virtualmachineimage_live_test.go | 93 ++++ .../virtualmachines_client_live_test.go | 312 ----------- .../virtualmachinescaleset_live_test.go | 399 ++++++++++++++ ...irtualmachinescalesets_client_live_test.go | 195 ------- 23 files changed, 3202 insertions(+), 634 deletions(-) create mode 100644 sdk/resourcemanager/compute/armcompute/availabilityset_live_test.go delete mode 100644 sdk/resourcemanager/compute/armcompute/availabilitysets_client_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/capacityreservation_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/computerpcommon_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/dedicatedhost_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/disk_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/diskaccess_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/gallery_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/proximityplacementgroup_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/restorepoint_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/runcommand_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/skus_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/snapshot_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/sshpublickey_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/virtualmachine_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/virtualmachineextensionimage_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/virtualmachineimage_live_test.go delete mode 100644 sdk/resourcemanager/compute/armcompute/virtualmachines_client_live_test.go create mode 100644 sdk/resourcemanager/compute/armcompute/virtualmachinescaleset_live_test.go delete mode 100644 sdk/resourcemanager/compute/armcompute/virtualmachinescalesets_client_live_test.go diff --git a/sdk/resourcemanager/compute/armcompute/assets.json b/sdk/resourcemanager/compute/armcompute/assets.json index 740c95e53803..ac6ee8d491e5 100644 --- a/sdk/resourcemanager/compute/armcompute/assets.json +++ b/sdk/resourcemanager/compute/armcompute/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/resourcemanager/compute/armcompute", - "Tag": "go/resourcemanager/compute/armcompute_7dca156240" + "Tag": "go/resourcemanager/compute/armcompute_d7f582b36e" } diff --git a/sdk/resourcemanager/compute/armcompute/availabilityset_live_test.go b/sdk/resourcemanager/compute/armcompute/availabilityset_live_test.go new file mode 100644 index 000000000000..938bb22c9b5a --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/availabilityset_live_test.go @@ -0,0 +1,117 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type AvailabilitySetTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + location string + resourceGroupName string + subscriptionId string + availabilitySetName string +} + +func (testsuite *AvailabilitySetTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.availabilitySetName = testutil.GenerateAlphaNumericID(testsuite.T(), "availabili", 6) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *AvailabilitySetTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestAvailabilitySetTestSuite(t *testing.T) { + suite.Run(t, new(AvailabilitySetTestSuite)) +} + +// Microsoft.Compute/availabilitySets +func (testsuite *AvailabilitySetTestSuite) TestAvailabilitySets() { + var err error + // From step AvailabilitySets_CreateOrUpdate + fmt.Println("Call operation: AvailabilitySets_CreateOrUpdate") + availabilitySetsClient, err := armcompute.NewAvailabilitySetsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = availabilitySetsClient.CreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.availabilitySetName, armcompute.AvailabilitySet{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.AvailabilitySetProperties{ + PlatformFaultDomainCount: to.Ptr[int32](2), + PlatformUpdateDomainCount: to.Ptr[int32](20), + }, + }, nil) + testsuite.Require().NoError(err) + + // From step AvailabilitySets_ListBySubscription + fmt.Println("Call operation: AvailabilitySets_ListBySubscription") + availabilitySetsClientNewListBySubscriptionPager := availabilitySetsClient.NewListBySubscriptionPager(&armcompute.AvailabilitySetsClientListBySubscriptionOptions{Expand: nil}) + for availabilitySetsClientNewListBySubscriptionPager.More() { + _, err := availabilitySetsClientNewListBySubscriptionPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step AvailabilitySets_List + fmt.Println("Call operation: AvailabilitySets_List") + availabilitySetsClientNewListPager := availabilitySetsClient.NewListPager(testsuite.resourceGroupName, nil) + for availabilitySetsClientNewListPager.More() { + _, err := availabilitySetsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step AvailabilitySets_Get + fmt.Println("Call operation: AvailabilitySets_Get") + _, err = availabilitySetsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.availabilitySetName, nil) + testsuite.Require().NoError(err) + + // From step AvailabilitySets_ListAvailableSizes + fmt.Println("Call operation: AvailabilitySets_ListAvailableSizes") + availabilitySetsClientNewListAvailableSizesPager := availabilitySetsClient.NewListAvailableSizesPager(testsuite.resourceGroupName, testsuite.availabilitySetName, nil) + for availabilitySetsClientNewListAvailableSizesPager.More() { + _, err := availabilitySetsClientNewListAvailableSizesPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step AvailabilitySets_Update + fmt.Println("Call operation: AvailabilitySets_Update") + _, err = availabilitySetsClient.Update(testsuite.ctx, testsuite.resourceGroupName, testsuite.availabilitySetName, armcompute.AvailabilitySetUpdate{}, nil) + testsuite.Require().NoError(err) + + // From step AvailabilitySets_Delete + fmt.Println("Call operation: AvailabilitySets_Delete") + _, err = availabilitySetsClient.Delete(testsuite.ctx, testsuite.resourceGroupName, testsuite.availabilitySetName, nil) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/availabilitysets_client_live_test.go b/sdk/resourcemanager/compute/armcompute/availabilitysets_client_live_test.go deleted file mode 100644 index 014e6b7e340c..000000000000 --- a/sdk/resourcemanager/compute/armcompute/availabilitysets_client_live_test.go +++ /dev/null @@ -1,120 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -package armcompute_test - -import ( - "context" - "fmt" - "testing" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" - "github.com/stretchr/testify/suite" -) - -type AvailabilitySetsClientTestSuite struct { - suite.Suite - - ctx context.Context - cred azcore.TokenCredential - options *arm.ClientOptions - location string - resourceGroupName string - subscriptionID string -} - -func (testsuite *AvailabilitySetsClientTestSuite) SetupSuite() { - testsuite.ctx = context.Background() - testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") - testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") - resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) - testsuite.Require().NoError(err) - testsuite.resourceGroupName = *resourceGroup.Name -} - -func (testsuite *AvailabilitySetsClientTestSuite) TearDownSuite() { - _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.resourceGroupName) - testsuite.Require().NoError(err) - testutil.StopRecording(testsuite.T()) -} - -func TestAvailabilitySetsClient(t *testing.T) { - suite.Run(t, new(AvailabilitySetsClientTestSuite)) -} - -func (testsuite *AvailabilitySetsClientTestSuite) TestAvailabilitySetsCRUD() { - // create availability sets - fmt.Println("Call operation: AvailabilitySets_CreateOrUpdate") - client, err := armcompute.NewAvailabilitySetsClient(testsuite.subscriptionID, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - name := "go-test-availability" - resp, err := client.CreateOrUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - name, - armcompute.AvailabilitySet{ - Location: to.Ptr("westus"), - SKU: &armcompute.SKU{ - Name: to.Ptr(string(armcompute.AvailabilitySetSKUTypesAligned)), - }, - Properties: &armcompute.AvailabilitySetProperties{ - PlatformFaultDomainCount: to.Ptr[int32](1), - PlatformUpdateDomainCount: to.Ptr[int32](1), - }, - }, - nil, - ) - testsuite.Require().NoError(err) - testsuite.Require().Equal(*resp.Name, name) - - // get - fmt.Println("Call operation: AvailabilitySets_Get") - getResp, err := client.Get(testsuite.ctx, testsuite.resourceGroupName, name, nil) - testsuite.Require().NoError(err) - testsuite.Require().Equal(*getResp.Name, name) - - // list - fmt.Println("Call operation: AvailabilitySets_List") - listPager := client.NewListPager(testsuite.resourceGroupName, nil) - testsuite.Require().True(listPager.More()) - - // list available size - fmt.Println("Call operation: AvailabilitySets_ListAvailableSize") - listResp := client.NewListAvailableSizesPager(testsuite.resourceGroupName, name, nil) - testsuite.Require().True(listResp.More()) - - // list by subscription - fmt.Println("Call operation: AvailabilitySets_ListBySubscription") - listBySubscription := client.NewListBySubscriptionPager(nil) - testsuite.Require().True(listBySubscription.More()) - - // update - fmt.Println("Call operation: AvailabilitySets_Update") - updateResp, err := client.Update( - testsuite.ctx, - testsuite.resourceGroupName, - name, - armcompute.AvailabilitySetUpdate{ - Tags: map[string]*string{ - "tag": to.Ptr("value"), - }, - }, - nil, - ) - testsuite.Require().NoError(err) - testsuite.Require().Equal(name, *updateResp.Name) - - // delete - fmt.Println("Call operation: AvailabilitySets_Delete") - _, err = client.Delete(testsuite.ctx, testsuite.resourceGroupName, name, nil) - testsuite.Require().NoError(err) -} diff --git a/sdk/resourcemanager/compute/armcompute/capacityreservation_live_test.go b/sdk/resourcemanager/compute/armcompute/capacityreservation_live_test.go new file mode 100644 index 000000000000..768fca18eae0 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/capacityreservation_live_test.go @@ -0,0 +1,122 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type CapacityReservationTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + capacityReservationGroupName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *CapacityReservationTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.capacityReservationGroupName = testutil.GenerateAlphaNumericID(testsuite.T(), "capacityre", 6) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *CapacityReservationTestSuite) TearDownSuite() { + testsuite.Cleanup() + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestCapacityReservationTestSuite(t *testing.T) { + suite.Run(t, new(CapacityReservationTestSuite)) +} + +func (testsuite *CapacityReservationTestSuite) Prepare() { + var err error + // From step CapacityReservationGroups_CreateOrUpdate + fmt.Println("Call operation: CapacityReservationGroups_CreateOrUpdate") + capacityReservationGroupsClient, err := armcompute.NewCapacityReservationGroupsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = capacityReservationGroupsClient.CreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.capacityReservationGroupName, armcompute.CapacityReservationGroup{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{ + "department": to.Ptr("finance"), + }, + Zones: []*string{ + to.Ptr("1"), + to.Ptr("2")}, + }, nil) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/capacityReservationGroups +func (testsuite *CapacityReservationTestSuite) TestCapacityReservationGroups() { + var err error + // From step CapacityReservationGroups_ListBySubscription + fmt.Println("Call operation: CapacityReservationGroups_ListBySubscription") + capacityReservationGroupsClient, err := armcompute.NewCapacityReservationGroupsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + capacityReservationGroupsClientNewListBySubscriptionPager := capacityReservationGroupsClient.NewListBySubscriptionPager(&armcompute.CapacityReservationGroupsClientListBySubscriptionOptions{Expand: to.Ptr(armcompute.ExpandTypesForGetCapacityReservationGroupsVirtualMachinesRef)}) + for capacityReservationGroupsClientNewListBySubscriptionPager.More() { + _, err := capacityReservationGroupsClientNewListBySubscriptionPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step CapacityReservationGroups_ListByResourceGroup + fmt.Println("Call operation: CapacityReservationGroups_ListByResourceGroup") + capacityReservationGroupsClientNewListByResourceGroupPager := capacityReservationGroupsClient.NewListByResourceGroupPager(testsuite.resourceGroupName, &armcompute.CapacityReservationGroupsClientListByResourceGroupOptions{Expand: to.Ptr(armcompute.ExpandTypesForGetCapacityReservationGroupsVirtualMachinesRef)}) + for capacityReservationGroupsClientNewListByResourceGroupPager.More() { + _, err := capacityReservationGroupsClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step CapacityReservationGroups_Get + fmt.Println("Call operation: CapacityReservationGroups_Get") + _, err = capacityReservationGroupsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.capacityReservationGroupName, &armcompute.CapacityReservationGroupsClientGetOptions{Expand: to.Ptr(armcompute.CapacityReservationGroupInstanceViewTypesInstanceView)}) + testsuite.Require().NoError(err) + + // From step CapacityReservationGroups_Update + fmt.Println("Call operation: CapacityReservationGroups_Update") + _, err = capacityReservationGroupsClient.Update(testsuite.ctx, testsuite.resourceGroupName, testsuite.capacityReservationGroupName, armcompute.CapacityReservationGroupUpdate{}, nil) + testsuite.Require().NoError(err) +} + +func (testsuite *CapacityReservationTestSuite) Cleanup() { + var err error + // From step CapacityReservationGroups_Delete + fmt.Println("Call operation: CapacityReservationGroups_Delete") + capacityReservationGroupsClient, err := armcompute.NewCapacityReservationGroupsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = capacityReservationGroupsClient.Delete(testsuite.ctx, testsuite.resourceGroupName, testsuite.capacityReservationGroupName, nil) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/computerpcommon_live_test.go b/sdk/resourcemanager/compute/armcompute/computerpcommon_live_test.go new file mode 100644 index 000000000000..77ebfe856aca --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/computerpcommon_live_test.go @@ -0,0 +1,100 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type ComputeRpCommonTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *ComputeRpCommonTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *ComputeRpCommonTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestComputeRpCommonTestSuite(t *testing.T) { + suite.Run(t, new(ComputeRpCommonTestSuite)) +} + +// Microsoft.Compute/operations +func (testsuite *ComputeRpCommonTestSuite) TestOperations() { + var err error + // From step Operations_List + fmt.Println("Call operation: Operations_List") + operationsClient, err := armcompute.NewOperationsClient(testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + operationsClientNewListPager := operationsClient.NewListPager(nil) + for operationsClientNewListPager.More() { + _, err := operationsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} + +// Microsoft.Compute/locations/{location}/usages +func (testsuite *ComputeRpCommonTestSuite) TestUsage() { + var err error + // From step Usage_List + fmt.Println("Call operation: Usage_List") + usageClient, err := armcompute.NewUsageClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + usageClientNewListPager := usageClient.NewListPager(testsuite.location, nil) + for usageClientNewListPager.More() { + _, err := usageClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} + +// Microsoft.Compute/locations/{location}/vmSizes +func (testsuite *ComputeRpCommonTestSuite) TestVirtualMachineSizes() { + var err error + // From step VirtualMachineSizes_List + fmt.Println("Call operation: VirtualMachineSizes_List") + virtualMachineSizesClient, err := armcompute.NewVirtualMachineSizesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachineSizesClientNewListPager := virtualMachineSizesClient.NewListPager(testsuite.location, nil) + for virtualMachineSizesClientNewListPager.More() { + _, err := virtualMachineSizesClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} diff --git a/sdk/resourcemanager/compute/armcompute/dedicatedhost_live_test.go b/sdk/resourcemanager/compute/armcompute/dedicatedhost_live_test.go new file mode 100644 index 000000000000..8852d1a2e308 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/dedicatedhost_live_test.go @@ -0,0 +1,174 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type DedicatedHostTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + hostGroupName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *DedicatedHostTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.hostGroupName = testutil.GenerateAlphaNumericID(testsuite.T(), "hostgroupn", 6) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *DedicatedHostTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestDedicatedHostTestSuite(t *testing.T) { + suite.Run(t, new(DedicatedHostTestSuite)) +} + +func (testsuite *DedicatedHostTestSuite) Prepare() { + var err error + // From step DedicatedHostGroups_CreateOrUpdate + fmt.Println("Call operation: DedicatedHostGroups_CreateOrUpdate") + dedicatedHostGroupsClient, err := armcompute.NewDedicatedHostGroupsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = dedicatedHostGroupsClient.CreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.hostGroupName, armcompute.DedicatedHostGroup{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{ + "department": to.Ptr("finance"), + }, + Properties: &armcompute.DedicatedHostGroupProperties{ + PlatformFaultDomainCount: to.Ptr[int32](3), + SupportAutomaticPlacement: to.Ptr(true), + }, + Zones: []*string{ + to.Ptr("1")}, + }, nil) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/hostGroups +func (testsuite *DedicatedHostTestSuite) TestDedicatedHostGroups() { + var err error + // From step DedicatedHostGroups_ListBySubscription + fmt.Println("Call operation: DedicatedHostGroups_ListBySubscription") + dedicatedHostGroupsClient, err := armcompute.NewDedicatedHostGroupsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + dedicatedHostGroupsClientNewListBySubscriptionPager := dedicatedHostGroupsClient.NewListBySubscriptionPager(nil) + for dedicatedHostGroupsClientNewListBySubscriptionPager.More() { + _, err := dedicatedHostGroupsClientNewListBySubscriptionPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DedicatedHostGroups_ListByResourceGroup + fmt.Println("Call operation: DedicatedHostGroups_ListByResourceGroup") + dedicatedHostGroupsClientNewListByResourceGroupPager := dedicatedHostGroupsClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for dedicatedHostGroupsClientNewListByResourceGroupPager.More() { + _, err := dedicatedHostGroupsClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DedicatedHostGroups_Get + fmt.Println("Call operation: DedicatedHostGroups_Get") + _, err = dedicatedHostGroupsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.hostGroupName, &armcompute.DedicatedHostGroupsClientGetOptions{Expand: nil}) + testsuite.Require().NoError(err) + + // From step DedicatedHostGroups_Update + fmt.Println("Call operation: DedicatedHostGroups_Update") + _, err = dedicatedHostGroupsClient.Update(testsuite.ctx, testsuite.resourceGroupName, testsuite.hostGroupName, armcompute.DedicatedHostGroupUpdate{}, nil) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/hostGroups/hosts +func (testsuite *DedicatedHostTestSuite) TestDedicatedHosts() { + hostName := testutil.GenerateAlphaNumericID(testsuite.T(), "hostname", 6) + var err error + // From step DedicatedHosts_CreateOrUpdate + fmt.Println("Call operation: DedicatedHosts_CreateOrUpdate") + dedicatedHostsClient, err := armcompute.NewDedicatedHostsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + dedicatedHostsClientCreateOrUpdateResponsePoller, err := dedicatedHostsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.hostGroupName, hostName, armcompute.DedicatedHost{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{ + "department": to.Ptr("HR"), + }, + Properties: &armcompute.DedicatedHostProperties{ + PlatformFaultDomain: to.Ptr[int32](1), + }, + SKU: &armcompute.SKU{ + Name: to.Ptr("DSv3-Type1"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, dedicatedHostsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step DedicatedHosts_ListByHostGroup + fmt.Println("Call operation: DedicatedHosts_ListByHostGroup") + dedicatedHostsClientNewListByHostGroupPager := dedicatedHostsClient.NewListByHostGroupPager(testsuite.resourceGroupName, testsuite.hostGroupName, nil) + for dedicatedHostsClientNewListByHostGroupPager.More() { + _, err := dedicatedHostsClientNewListByHostGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DedicatedHosts_Get + fmt.Println("Call operation: DedicatedHosts_Get") + _, err = dedicatedHostsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.hostGroupName, hostName, &armcompute.DedicatedHostsClientGetOptions{Expand: nil}) + testsuite.Require().NoError(err) + + // From step DedicatedHosts_Update + fmt.Println("Call operation: DedicatedHosts_Update") + dedicatedHostsClientUpdateResponsePoller, err := dedicatedHostsClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.hostGroupName, hostName, armcompute.DedicatedHostUpdate{}, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, dedicatedHostsClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step DedicatedHosts_Restart + fmt.Println("Call operation: DedicatedHosts_Restart") + dedicatedHostsClientRestartResponsePoller, err := dedicatedHostsClient.BeginRestart(testsuite.ctx, testsuite.resourceGroupName, testsuite.hostGroupName, hostName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, dedicatedHostsClientRestartResponsePoller) + testsuite.Require().NoError(err) + + // From step DedicatedHosts_Delete + fmt.Println("Call operation: DedicatedHosts_Delete") + dedicatedHostsClientDeleteResponsePoller, err := dedicatedHostsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.hostGroupName, hostName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, dedicatedHostsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/disk_live_test.go b/sdk/resourcemanager/compute/armcompute/disk_live_test.go new file mode 100644 index 000000000000..bedc48da779c --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/disk_live_test.go @@ -0,0 +1,137 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type DiskTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + diskName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *DiskTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.diskName = testutil.GenerateAlphaNumericID(testsuite.T(), "diskname", 6) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *DiskTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestDiskTestSuite(t *testing.T) { + suite.Run(t, new(DiskTestSuite)) +} + +// Microsoft.Compute/disks/{diskName} +func (testsuite *DiskTestSuite) TestDisks() { + var err error + // From step Disks_CreateOrUpdate + fmt.Println("Call operation: Disks_CreateOrUpdate") + disksClient, err := armcompute.NewDisksClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + disksClientCreateOrUpdateResponsePoller, err := disksClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskName, armcompute.Disk{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.DiskProperties{ + CreationData: &armcompute.CreationData{ + CreateOption: to.Ptr(armcompute.DiskCreateOptionEmpty), + }, + DiskSizeGB: to.Ptr[int32](200), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, disksClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step Disks_List + fmt.Println("Call operation: Disks_List") + disksClientNewListPager := disksClient.NewListPager(nil) + for disksClientNewListPager.More() { + _, err := disksClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Disks_ListByResourceGroup + fmt.Println("Call operation: Disks_ListByResourceGroup") + disksClientNewListByResourceGroupPager := disksClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for disksClientNewListByResourceGroupPager.More() { + _, err := disksClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Disks_Get + fmt.Println("Call operation: Disks_Get") + _, err = disksClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskName, nil) + testsuite.Require().NoError(err) + + // From step Disks_Update + fmt.Println("Call operation: Disks_Update") + disksClientUpdateResponsePoller, err := disksClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskName, armcompute.DiskUpdate{ + Properties: &armcompute.DiskUpdateProperties{ + NetworkAccessPolicy: to.Ptr(armcompute.NetworkAccessPolicyAllowAll), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, disksClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step Disks_GrantAccess + fmt.Println("Call operation: Disks_GrantAccess") + disksClientGrantAccessResponsePoller, err := disksClient.BeginGrantAccess(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskName, armcompute.GrantAccessData{ + Access: to.Ptr(armcompute.AccessLevelRead), + DurationInSeconds: to.Ptr[int32](300), + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, disksClientGrantAccessResponsePoller) + testsuite.Require().NoError(err) + + // From step Disks_RevokeAccess + fmt.Println("Call operation: Disks_RevokeAccess") + disksClientRevokeAccessResponsePoller, err := disksClient.BeginRevokeAccess(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, disksClientRevokeAccessResponsePoller) + testsuite.Require().NoError(err) + + // From step Disks_Delete + fmt.Println("Call operation: Disks_Delete") + disksClientDeleteResponsePoller, err := disksClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, disksClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/diskaccess_live_test.go b/sdk/resourcemanager/compute/armcompute/diskaccess_live_test.go new file mode 100644 index 000000000000..8819fc58dd5c --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/diskaccess_live_test.go @@ -0,0 +1,129 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type DiskAccessTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + diskAccessName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *DiskAccessTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.diskAccessName = testutil.GenerateAlphaNumericID(testsuite.T(), "diskaccess", 6) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *DiskAccessTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestDiskAccessTestSuite(t *testing.T) { + suite.Run(t, new(DiskAccessTestSuite)) +} + +// Microsoft.Compute/diskAccesses/{diskAccessName} +func (testsuite *DiskAccessTestSuite) TestDiskAccesses() { + var err error + // From step DiskAccesses_CreateOrUpdate + fmt.Println("Call operation: DiskAccesses_CreateOrUpdate") + diskAccessesClient, err := armcompute.NewDiskAccessesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + diskAccessesClientCreateOrUpdateResponsePoller, err := diskAccessesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskAccessName, armcompute.DiskAccess{ + Location: to.Ptr(testsuite.location), + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, diskAccessesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step DiskAccesses_List + fmt.Println("Call operation: DiskAccesses_List") + diskAccessesClientNewListPager := diskAccessesClient.NewListPager(nil) + for diskAccessesClientNewListPager.More() { + _, err := diskAccessesClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DiskAccesses_ListPrivateEndpointConnections + fmt.Println("Call operation: DiskAccesses_ListPrivateEndpointConnections") + diskAccessesClientNewListPrivateEndpointConnectionsPager := diskAccessesClient.NewListPrivateEndpointConnectionsPager(testsuite.resourceGroupName, testsuite.diskAccessName, nil) + for diskAccessesClientNewListPrivateEndpointConnectionsPager.More() { + _, err := diskAccessesClientNewListPrivateEndpointConnectionsPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DiskAccesses_GetPrivateLinkResources + fmt.Println("Call operation: DiskAccesses_GetPrivateLinkResources") + _, err = diskAccessesClient.GetPrivateLinkResources(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskAccessName, nil) + testsuite.Require().NoError(err) + + // From step DiskAccesses_ListByResourceGroup + fmt.Println("Call operation: DiskAccesses_ListByResourceGroup") + diskAccessesClientNewListByResourceGroupPager := diskAccessesClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for diskAccessesClientNewListByResourceGroupPager.More() { + _, err := diskAccessesClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DiskAccesses_Get + fmt.Println("Call operation: DiskAccesses_Get") + _, err = diskAccessesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskAccessName, nil) + testsuite.Require().NoError(err) + + // From step DiskAccesses_Update + fmt.Println("Call operation: DiskAccesses_Update") + diskAccessesClientUpdateResponsePoller, err := diskAccessesClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskAccessName, armcompute.DiskAccessUpdate{ + Tags: map[string]*string{ + "department": to.Ptr("Development"), + "project": to.Ptr("PrivateEndpoints"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, diskAccessesClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step DiskAccesses_Delete + fmt.Println("Call operation: DiskAccesses_Delete") + diskAccessesClientDeleteResponsePoller, err := diskAccessesClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.diskAccessName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, diskAccessesClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/gallery_live_test.go b/sdk/resourcemanager/compute/armcompute/gallery_live_test.go new file mode 100644 index 000000000000..a62b519b428b --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/gallery_live_test.go @@ -0,0 +1,265 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type GalleryTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + galleryApplicationName string + galleryImageName string + galleryName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *GalleryTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.galleryApplicationName = testutil.GenerateAlphaNumericID(testsuite.T(), "galleryapp", 6) + testsuite.galleryImageName = testutil.GenerateAlphaNumericID(testsuite.T(), "galleryima", 6) + testsuite.galleryName = testutil.GenerateAlphaNumericID(testsuite.T(), "gallerynam", 6) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *GalleryTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestGalleryTestSuite(t *testing.T) { + suite.Run(t, new(GalleryTestSuite)) +} + +func (testsuite *GalleryTestSuite) Prepare() { + var err error + // From step Galleries_CreateOrUpdate + fmt.Println("Call operation: Galleries_CreateOrUpdate") + galleriesClient, err := armcompute.NewGalleriesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + galleriesClientCreateOrUpdateResponsePoller, err := galleriesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, armcompute.Gallery{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.GalleryProperties{ + Description: to.Ptr("This is the gallery description."), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, galleriesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/galleries/{galleryName} +func (testsuite *GalleryTestSuite) TestGalleries() { + var err error + // From step Galleries_List + fmt.Println("Call operation: Galleries_List") + galleriesClient, err := armcompute.NewGalleriesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + galleriesClientNewListPager := galleriesClient.NewListPager(nil) + for galleriesClientNewListPager.More() { + _, err := galleriesClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Galleries_ListByResourceGroup + fmt.Println("Call operation: Galleries_ListByResourceGroup") + galleriesClientNewListByResourceGroupPager := galleriesClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for galleriesClientNewListByResourceGroupPager.More() { + _, err := galleriesClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Galleries_Get + fmt.Println("Call operation: Galleries_Get") + _, err = galleriesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, &armcompute.GalleriesClientGetOptions{Select: nil, + Expand: nil, + }) + testsuite.Require().NoError(err) + + // From step Galleries_Update + fmt.Println("Call operation: Galleries_Update") + galleriesClientUpdateResponsePoller, err := galleriesClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, armcompute.GalleryUpdate{ + Properties: &armcompute.GalleryProperties{ + Description: to.Ptr("This is the gallery description."), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, galleriesClientUpdateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/galleries/{galleryName}/images/{galleryImageName} +func (testsuite *GalleryTestSuite) TestGalleryImages() { + var err error + // From step GalleryImages_CreateOrUpdate + fmt.Println("Call operation: GalleryImages_CreateOrUpdate") + galleryImagesClient, err := armcompute.NewGalleryImagesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + galleryImagesClientCreateOrUpdateResponsePoller, err := galleryImagesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, testsuite.galleryImageName, armcompute.GalleryImage{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.GalleryImageProperties{ + HyperVGeneration: to.Ptr(armcompute.HyperVGenerationV1), + Identifier: &armcompute.GalleryImageIdentifier{ + Offer: to.Ptr("myOfferName"), + Publisher: to.Ptr("myPublisherName"), + SKU: to.Ptr("mySkuName"), + }, + OSState: to.Ptr(armcompute.OperatingSystemStateTypesGeneralized), + OSType: to.Ptr(armcompute.OperatingSystemTypesWindows), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, galleryImagesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step GalleryImages_ListByGallery + fmt.Println("Call operation: GalleryImages_ListByGallery") + galleryImagesClientNewListByGalleryPager := galleryImagesClient.NewListByGalleryPager(testsuite.resourceGroupName, testsuite.galleryName, nil) + for galleryImagesClientNewListByGalleryPager.More() { + _, err := galleryImagesClientNewListByGalleryPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step GalleryImages_Get + fmt.Println("Call operation: GalleryImages_Get") + _, err = galleryImagesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, testsuite.galleryImageName, nil) + testsuite.Require().NoError(err) + + // From step GalleryImages_Update + fmt.Println("Call operation: GalleryImages_Update") + galleryImagesClientUpdateResponsePoller, err := galleryImagesClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, testsuite.galleryImageName, armcompute.GalleryImageUpdate{ + Tags: map[string]*string{ + "0": to.Ptr("[object Object]"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, galleryImagesClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step GalleryImages_Delete + fmt.Println("Call operation: GalleryImages_Delete") + galleryImagesClientDeleteResponsePoller, err := galleryImagesClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, testsuite.galleryImageName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, galleryImagesClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName} +func (testsuite *GalleryTestSuite) TestGalleryApplications() { + var err error + // From step GalleryApplications_CreateOrUpdate + fmt.Println("Call operation: GalleryApplications_CreateOrUpdate") + galleryApplicationsClient, err := armcompute.NewGalleryApplicationsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + galleryApplicationsClientCreateOrUpdateResponsePoller, err := galleryApplicationsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, testsuite.galleryApplicationName, armcompute.GalleryApplication{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.GalleryApplicationProperties{ + Description: to.Ptr("This is the gallery application description."), + CustomActions: []*armcompute.GalleryApplicationCustomAction{ + { + Name: to.Ptr("myCustomAction"), + Description: to.Ptr("This is the custom action description."), + Parameters: []*armcompute.GalleryApplicationCustomActionParameter{ + { + Name: to.Ptr("myCustomActionParameter"), + Type: to.Ptr(armcompute.GalleryApplicationCustomActionParameterTypeString), + Description: to.Ptr("This is the description of the parameter"), + DefaultValue: to.Ptr("default value of parameter."), + Required: to.Ptr(false), + }}, + Script: to.Ptr("myCustomActionScript"), + }}, + Eula: to.Ptr("This is the gallery application EULA."), + PrivacyStatementURI: to.Ptr("myPrivacyStatementUri}"), + ReleaseNoteURI: to.Ptr("myReleaseNoteUri"), + SupportedOSType: to.Ptr(armcompute.OperatingSystemTypesWindows), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, galleryApplicationsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step GalleryApplications_ListByGallery + fmt.Println("Call operation: GalleryApplications_ListByGallery") + galleryApplicationsClientNewListByGalleryPager := galleryApplicationsClient.NewListByGalleryPager(testsuite.resourceGroupName, testsuite.galleryName, nil) + for galleryApplicationsClientNewListByGalleryPager.More() { + _, err := galleryApplicationsClientNewListByGalleryPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step GalleryApplications_Get + fmt.Println("Call operation: GalleryApplications_Get") + _, err = galleryApplicationsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, testsuite.galleryApplicationName, nil) + testsuite.Require().NoError(err) + + // From step GalleryApplications_Update + fmt.Println("Call operation: GalleryApplications_Update") + galleryApplicationsClientUpdateResponsePoller, err := galleryApplicationsClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, testsuite.galleryApplicationName, armcompute.GalleryApplicationUpdate{ + Properties: &armcompute.GalleryApplicationProperties{ + Description: to.Ptr("This is the gallery application description."), + CustomActions: []*armcompute.GalleryApplicationCustomAction{ + { + Name: to.Ptr("myCustomAction"), + Description: to.Ptr("This is the custom action description."), + Parameters: []*armcompute.GalleryApplicationCustomActionParameter{ + { + Name: to.Ptr("myCustomActionParameter"), + Type: to.Ptr(armcompute.GalleryApplicationCustomActionParameterTypeString), + Description: to.Ptr("This is the description of the parameter"), + DefaultValue: to.Ptr("default value of parameter."), + Required: to.Ptr(false), + }}, + Script: to.Ptr("myCustomActionScript"), + }}, + Eula: to.Ptr("This is the gallery application EULA."), + PrivacyStatementURI: to.Ptr("myPrivacyStatementUri}"), + ReleaseNoteURI: to.Ptr("myReleaseNoteUri"), + SupportedOSType: to.Ptr(armcompute.OperatingSystemTypesWindows), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, galleryApplicationsClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step GalleryApplications_Delete + fmt.Println("Call operation: GalleryApplications_Delete") + galleryApplicationsClientDeleteResponsePoller, err := galleryApplicationsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.galleryName, testsuite.galleryApplicationName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, galleryApplicationsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/go.mod b/sdk/resourcemanager/compute/armcompute/go.mod index 911c7d63ec64..3527d6bde3ca 100644 --- a/sdk/resourcemanager/compute/armcompute/go.mod +++ b/sdk/resourcemanager/compute/armcompute/go.mod @@ -6,13 +6,12 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.0.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 github.com/stretchr/testify v1.7.0 ) require ( github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect - github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dnaeon/go-vcr v1.1.0 // indirect diff --git a/sdk/resourcemanager/compute/armcompute/go.sum b/sdk/resourcemanager/compute/armcompute/go.sum index bf1cdbf4fff0..69e6a668b452 100644 --- a/sdk/resourcemanager/compute/armcompute/go.sum +++ b/sdk/resourcemanager/compute/armcompute/go.sum @@ -6,10 +6,9 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6U github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.0.0 h1:nBy98uKOIfun5z6wx6jwWLrULcM0+cjBalBFZlEZ7CA= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.0.0/go.mod h1:243D9iHbcQXoFUtgHJwL7gl2zx1aDuDMjvBZVGr2uW0= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8= -github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 h1:7CBQ+Ei8SP2c6ydQTGCCrS35bDxgTMfoP2miAwK++OU= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1/go.mod h1:c/wcGeGx5FUPbM/JltUYHZcKmigwyVLJlDq+4HdtXaw= github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 h1:VgSJlZH5u0k2qxSpqyghcFQKmvYckj46uymKK5XzkBM= github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0/go.mod h1:BDJ5qMFKx9DugEg3+uQSDCdbYPr5s9vBTrL9P8TpqOU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/sdk/resourcemanager/compute/armcompute/proximityplacementgroup_live_test.go b/sdk/resourcemanager/compute/armcompute/proximityplacementgroup_live_test.go new file mode 100644 index 000000000000..47694732ad4b --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/proximityplacementgroup_live_test.go @@ -0,0 +1,118 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type ProximityPlacementGroupTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + location string + proximityPlacementGroupName string + resourceGroupName string + subscriptionId string +} + +func (testsuite *ProximityPlacementGroupTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.proximityPlacementGroupName = testutil.GenerateAlphaNumericID(testsuite.T(), "proximityp", 6) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *ProximityPlacementGroupTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestProximityPlacementGroupTestSuite(t *testing.T) { + suite.Run(t, new(ProximityPlacementGroupTestSuite)) +} + +// Microsoft.Compute/proximityPlacementGroups +func (testsuite *ProximityPlacementGroupTestSuite) TestProximityPlacementGroups() { + var err error + // From step ProximityPlacementGroups_CreateOrUpdate + fmt.Println("Call operation: ProximityPlacementGroups_CreateOrUpdate") + proximityPlacementGroupsClient, err := armcompute.NewProximityPlacementGroupsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = proximityPlacementGroupsClient.CreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.proximityPlacementGroupName, armcompute.ProximityPlacementGroup{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.ProximityPlacementGroupProperties{ + Intent: &armcompute.ProximityPlacementGroupPropertiesIntent{ + VMSizes: []*string{ + to.Ptr("Basic_A0"), + to.Ptr("Basic_A2")}, + }, + ProximityPlacementGroupType: to.Ptr(armcompute.ProximityPlacementGroupTypeStandard), + }, + Zones: []*string{ + to.Ptr("1")}, + }, nil) + testsuite.Require().NoError(err) + + // From step ProximityPlacementGroups_ListBySubscription + fmt.Println("Call operation: ProximityPlacementGroups_ListBySubscription") + proximityPlacementGroupsClientNewListBySubscriptionPager := proximityPlacementGroupsClient.NewListBySubscriptionPager(nil) + for proximityPlacementGroupsClientNewListBySubscriptionPager.More() { + _, err := proximityPlacementGroupsClientNewListBySubscriptionPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step ProximityPlacementGroups_ListByResourceGroup + fmt.Println("Call operation: ProximityPlacementGroups_ListByResourceGroup") + proximityPlacementGroupsClientNewListByResourceGroupPager := proximityPlacementGroupsClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for proximityPlacementGroupsClientNewListByResourceGroupPager.More() { + _, err := proximityPlacementGroupsClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step ProximityPlacementGroups_Get + fmt.Println("Call operation: ProximityPlacementGroups_Get") + _, err = proximityPlacementGroupsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.proximityPlacementGroupName, &armcompute.ProximityPlacementGroupsClientGetOptions{IncludeColocationStatus: nil}) + testsuite.Require().NoError(err) + + // From step ProximityPlacementGroups_Update + fmt.Println("Call operation: ProximityPlacementGroups_Update") + _, err = proximityPlacementGroupsClient.Update(testsuite.ctx, testsuite.resourceGroupName, testsuite.proximityPlacementGroupName, armcompute.ProximityPlacementGroupUpdate{ + Tags: map[string]*string{ + "additionalProp1": to.Ptr("string"), + }, + }, nil) + testsuite.Require().NoError(err) + + // From step ProximityPlacementGroups_Delete + fmt.Println("Call operation: ProximityPlacementGroups_Delete") + _, err = proximityPlacementGroupsClient.Delete(testsuite.ctx, testsuite.resourceGroupName, testsuite.proximityPlacementGroupName, nil) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/restorepoint_live_test.go b/sdk/resourcemanager/compute/armcompute/restorepoint_live_test.go new file mode 100644 index 000000000000..cf14b432a779 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/restorepoint_live_test.go @@ -0,0 +1,291 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/stretchr/testify/suite" +) + +type RestorePointTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + adminUsername string + networkInterfaceId string + networkInterfaceName string + restorePointCollectionName string + virtaulMachineId string + virtualNetworksName string + vmName string + adminPassword string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *RestorePointTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.adminUsername = testutil.GenerateAlphaNumericID(testsuite.T(), "rp", 6) + testsuite.networkInterfaceName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmnicrp", 6) + testsuite.restorePointCollectionName = testutil.GenerateAlphaNumericID(testsuite.T(), "restorepoi", 6) + testsuite.virtualNetworksName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmvnetrp", 6) + testsuite.vmName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmnamerp", 6) + testsuite.adminPassword = testutil.GetEnv("ADMIN_PASSWORD", "") + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *RestorePointTestSuite) TearDownSuite() { + testsuite.Cleanup() + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestRestorePointTestSuite(t *testing.T) { + suite.Run(t, new(RestorePointTestSuite)) +} + +func (testsuite *RestorePointTestSuite) Prepare() { + var err error + // From step Create_NetworkInterface + template := map[string]any{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "outputs": map[string]any{ + "networkInterfaceId": map[string]any{ + "type": "string", + "value": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]", + }, + }, + "parameters": map[string]any{ + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "networkInterfaceName": map[string]any{ + "type": "string", + "defaultValue": testsuite.networkInterfaceName, + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": testsuite.virtualNetworksName, + }, + }, + "resources": []any{ + map[string]any{ + "name": "[parameters('virtualNetworksName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2021-05-01", + "location": "[parameters('location')]", + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ + "10.0.0.0/16", + }, + }, + "subnets": []any{ + map[string]any{ + "name": "default", + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + }, + }, + }, + }, + }, + map[string]any{ + "name": "[parameters('networkInterfaceName')]", + "type": "Microsoft.Network/networkInterfaces", + "apiVersion": "2021-08-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworksName'))]", + }, + "location": "[parameters('location')]", + "properties": map[string]any{ + "ipConfigurations": []any{ + map[string]any{ + "name": "Ipv4config", + "properties": map[string]any{ + "subnet": map[string]any{ + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + }, + }, + }, + }, + }, + }, + } + deployment := armresources.Deployment{ + Properties: &armresources.DeploymentProperties{ + Template: template, + Mode: to.Ptr(armresources.DeploymentModeIncremental), + }, + } + deploymentExtend, err := testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_NetworkInterface", &deployment) + testsuite.Require().NoError(err) + testsuite.networkInterfaceId = deploymentExtend.Properties.Outputs.(map[string]interface{})["networkInterfaceId"].(map[string]interface{})["value"].(string) + + // From step VirtualMachines_CreateOrUpdate + fmt.Println("Call operation: VirtualMachines_CreateOrUpdate") + virtualMachinesClient, err := armcompute.NewVirtualMachinesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachinesClientCreateOrUpdateResponsePoller, err := virtualMachinesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, armcompute.VirtualMachine{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.VirtualMachineProperties{ + HardwareProfile: &armcompute.HardwareProfile{ + VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2), + }, + NetworkProfile: &armcompute.NetworkProfile{ + NetworkInterfaces: []*armcompute.NetworkInterfaceReference{ + { + ID: to.Ptr(testsuite.networkInterfaceId), + Properties: &armcompute.NetworkInterfaceReferenceProperties{ + Primary: to.Ptr(true), + }, + }}, + }, + OSProfile: &armcompute.OSProfile{ + AdminPassword: to.Ptr(testsuite.adminPassword), + AdminUsername: to.Ptr(testsuite.adminUsername), + ComputerName: to.Ptr(testsuite.vmName), + }, + StorageProfile: &armcompute.StorageProfile{ + ImageReference: &armcompute.ImageReference{ + Offer: to.Ptr("WindowsServer"), + Publisher: to.Ptr("MicrosoftWindowsServer"), + SKU: to.Ptr("2016-Datacenter"), + Version: to.Ptr("latest"), + }, + OSDisk: &armcompute.OSDisk{ + Name: to.Ptr(testsuite.vmName + "osdisk"), + Caching: to.Ptr(armcompute.CachingTypesReadWrite), + CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage), + ManagedDisk: &armcompute.ManagedDiskParameters{ + StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS), + }, + }, + }, + }, + }, nil) + testsuite.Require().NoError(err) + var virtualMachinesClientCreateOrUpdateResponse *armcompute.VirtualMachinesClientCreateOrUpdateResponse + virtualMachinesClientCreateOrUpdateResponse, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + testsuite.virtaulMachineId = *virtualMachinesClientCreateOrUpdateResponse.ID + + // From step RestorePointCollections_CreateOrUpdate + fmt.Println("Call operation: RestorePointCollections_CreateOrUpdate") + restorePointCollectionsClient, err := armcompute.NewRestorePointCollectionsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = restorePointCollectionsClient.CreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.restorePointCollectionName, armcompute.RestorePointCollection{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{ + "myTag1": to.Ptr("tagValue1"), + }, + Properties: &armcompute.RestorePointCollectionProperties{ + Source: &armcompute.RestorePointCollectionSourceProperties{ + ID: to.Ptr(testsuite.virtaulMachineId), + }, + }, + }, nil) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/restorePointCollections +func (testsuite *RestorePointTestSuite) TestRestorePointCollections() { + var err error + // From step RestorePointCollections_ListAll + fmt.Println("Call operation: RestorePointCollections_ListAll") + restorePointCollectionsClient, err := armcompute.NewRestorePointCollectionsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + restorePointCollectionsClientNewListAllPager := restorePointCollectionsClient.NewListAllPager(nil) + for restorePointCollectionsClientNewListAllPager.More() { + _, err := restorePointCollectionsClientNewListAllPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step RestorePointCollections_List + fmt.Println("Call operation: RestorePointCollections_List") + restorePointCollectionsClientNewListPager := restorePointCollectionsClient.NewListPager(testsuite.resourceGroupName, nil) + for restorePointCollectionsClientNewListPager.More() { + _, err := restorePointCollectionsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step RestorePointCollections_Get + fmt.Println("Call operation: RestorePointCollections_Get") + _, err = restorePointCollectionsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.restorePointCollectionName, &armcompute.RestorePointCollectionsClientGetOptions{Expand: nil}) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/restorePointCollections/restorePoints +func (testsuite *RestorePointTestSuite) TestRestorePoints() { + restorePointName := testutil.GenerateAlphaNumericID(testsuite.T(), "restorepoi", 6) + var err error + // From step RestorePoints_Create + fmt.Println("Call operation: RestorePoints_Create") + restorePointsClient, err := armcompute.NewRestorePointsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + restorePointsClientCreateResponsePoller, err := restorePointsClient.BeginCreate(testsuite.ctx, testsuite.resourceGroupName, testsuite.restorePointCollectionName, restorePointName, armcompute.RestorePoint{}, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, restorePointsClientCreateResponsePoller) + testsuite.Require().NoError(err) + + // From step RestorePoints_Get + fmt.Println("Call operation: RestorePoints_Get") + _, err = restorePointsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.restorePointCollectionName, restorePointName, &armcompute.RestorePointsClientGetOptions{Expand: nil}) + testsuite.Require().NoError(err) + + // From step RestorePoints_Delete + fmt.Println("Call operation: RestorePoints_Delete") + restorePointsClientDeleteResponsePoller, err := restorePointsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.restorePointCollectionName, restorePointName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, restorePointsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} + +func (testsuite *RestorePointTestSuite) Cleanup() { + var err error + // From step RestorePointCollections_Update + restorePointCollectionsClient, err := armcompute.NewRestorePointCollectionsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + fmt.Println("Call operation: RestorePointCollections_Update") + _, err = restorePointCollectionsClient.Update(testsuite.ctx, testsuite.resourceGroupName, testsuite.restorePointCollectionName, armcompute.RestorePointCollectionUpdate{}, nil) + testsuite.Require().NoError(err) + // From step RestorePointCollections_Delete + fmt.Println("Call operation: RestorePointCollections_Delete") + restorePointCollectionsClientDeleteResponsePoller, err := restorePointCollectionsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.restorePointCollectionName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, restorePointCollectionsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/runcommand_live_test.go b/sdk/resourcemanager/compute/armcompute/runcommand_live_test.go new file mode 100644 index 000000000000..6f7874afa6d4 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/runcommand_live_test.go @@ -0,0 +1,495 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/stretchr/testify/suite" +) + +type RunCommandTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + adminUsername string + networkInterfaceId string + networkInterfaceName string + subnetId string + virtualNetworkSubnetName string + virtualNetworksName string + vmName string + vmScaleSetName string + vmRunCommandName string + vmssRunCommandName string + adminPassword string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *RunCommandTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.adminUsername = testutil.GenerateAlphaNumericID(testsuite.T(), "rc", 6) + testsuite.networkInterfaceName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmnicrc", 6) + testsuite.virtualNetworkSubnetName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmssvnetnarc", 6) + testsuite.virtualNetworksName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmvnetrc", 6) + testsuite.vmName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmcommand", 6) + testsuite.vmScaleSetName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmscalesetcommand", 6) + testsuite.vmRunCommandName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmruncommand", 6) + testsuite.vmssRunCommandName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmssruncommand", 6) + testsuite.adminPassword = testutil.GetEnv("ADMIN_PASSWORD", "") + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *RunCommandTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestRunCommandTestSuite(t *testing.T) { + suite.Run(t, new(RunCommandTestSuite)) +} + +func (testsuite *RunCommandTestSuite) Prepare() { + var err error + // From step Create_NetworkInterface + template := map[string]any{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "outputs": map[string]any{ + "networkInterfaceId": map[string]any{ + "type": "string", + "value": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]", + }, + }, + "parameters": map[string]any{ + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "networkInterfaceName": map[string]any{ + "type": "string", + "defaultValue": testsuite.networkInterfaceName, + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": testsuite.virtualNetworksName, + }, + }, + "resources": []any{ + map[string]any{ + "name": "[parameters('virtualNetworksName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2021-05-01", + "location": "[parameters('location')]", + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ + "10.0.0.0/16", + }, + }, + "subnets": []any{ + map[string]any{ + "name": "default", + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + }, + }, + }, + }, + }, + map[string]any{ + "name": "[parameters('networkInterfaceName')]", + "type": "Microsoft.Network/networkInterfaces", + "apiVersion": "2021-08-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworksName'))]", + }, + "location": "[parameters('location')]", + "properties": map[string]any{ + "ipConfigurations": []any{ + map[string]any{ + "name": "Ipv4config", + "properties": map[string]any{ + "subnet": map[string]any{ + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + }, + }, + }, + }, + }, + }, + } + deployment := armresources.Deployment{ + Properties: &armresources.DeploymentProperties{ + Template: template, + Mode: to.Ptr(armresources.DeploymentModeIncremental), + }, + } + deploymentExtend, err := testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_NetworkInterface", &deployment) + testsuite.Require().NoError(err) + testsuite.networkInterfaceId = deploymentExtend.Properties.Outputs.(map[string]interface{})["networkInterfaceId"].(map[string]interface{})["value"].(string) + + // From step VirtualMachines_CreateOrUpdate + fmt.Println("Call operation: VirtualMachines_CreateOrUpdate") + virtualMachinesClient, err := armcompute.NewVirtualMachinesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachinesClientCreateOrUpdateResponsePoller, err := virtualMachinesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, armcompute.VirtualMachine{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.VirtualMachineProperties{ + HardwareProfile: &armcompute.HardwareProfile{ + VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2), + }, + NetworkProfile: &armcompute.NetworkProfile{ + NetworkInterfaces: []*armcompute.NetworkInterfaceReference{ + { + ID: to.Ptr(testsuite.networkInterfaceId), + Properties: &armcompute.NetworkInterfaceReferenceProperties{ + Primary: to.Ptr(true), + }, + }}, + }, + OSProfile: &armcompute.OSProfile{ + AdminPassword: to.Ptr(testsuite.adminPassword), + AdminUsername: to.Ptr(testsuite.adminUsername), + ComputerName: to.Ptr(testsuite.vmName), + }, + StorageProfile: &armcompute.StorageProfile{ + ImageReference: &armcompute.ImageReference{ + Offer: to.Ptr("WindowsServer"), + Publisher: to.Ptr("MicrosoftWindowsServer"), + SKU: to.Ptr("2016-Datacenter"), + Version: to.Ptr("latest"), + }, + OSDisk: &armcompute.OSDisk{ + Name: to.Ptr(testsuite.vmName + "osdisk"), + Caching: to.Ptr(armcompute.CachingTypesReadWrite), + CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage), + ManagedDisk: &armcompute.ManagedDiskParameters{ + StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS), + }, + }, + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step Create_NetworkAndSubnet + template = map[string]any{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "outputs": map[string]any{ + "subnetId": map[string]any{ + "type": "string", + "value": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkSubnetName'), 'default')]", + }, + }, + "parameters": map[string]any{ + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "virtualNetworkSubnetName": map[string]any{ + "type": "string", + "defaultValue": testsuite.virtualNetworkSubnetName, + }, + }, + "resources": []any{ + map[string]any{ + "name": "[parameters('virtualNetworkSubnetName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2021-05-01", + "location": "[parameters('location')]", + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ + "10.0.0.0/16", + }, + }, + "subnets": []any{ + map[string]any{ + "name": "default", + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + }, + }, + }, + }, + }, + }, + } + deployment = armresources.Deployment{ + Properties: &armresources.DeploymentProperties{ + Template: template, + Mode: to.Ptr(armresources.DeploymentModeIncremental), + }, + } + deploymentExtend, err = testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_NetworkAndSubnet", &deployment) + testsuite.Require().NoError(err) + testsuite.subnetId = deploymentExtend.Properties.Outputs.(map[string]interface{})["subnetId"].(map[string]interface{})["value"].(string) + + // From step VirtualMachineScaleSets_CreateOrUpdate + fmt.Println("Call operation: VirtualMachineScaleSets_CreateOrUpdate") + virtualMachineScaleSetsClient, err := armcompute.NewVirtualMachineScaleSetsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachineScaleSetsClientCreateOrUpdateResponsePoller, err := virtualMachineScaleSetsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, armcompute.VirtualMachineScaleSet{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.VirtualMachineScaleSetProperties{ + Overprovision: to.Ptr(true), + UpgradePolicy: &armcompute.UpgradePolicy{ + Mode: to.Ptr(armcompute.UpgradeModeManual), + }, + VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{ + NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{ + NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{ + { + Name: to.Ptr(testsuite.vmScaleSetName), + Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{ + EnableIPForwarding: to.Ptr(true), + IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{ + { + Name: to.Ptr(testsuite.vmScaleSetName), + Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{ + Subnet: &armcompute.APIEntityReference{ + ID: to.Ptr(testsuite.subnetId), + }, + }, + }}, + Primary: to.Ptr(true), + }, + }}, + }, + OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{ + AdminPassword: to.Ptr(testsuite.adminPassword), + AdminUsername: to.Ptr(testsuite.adminUsername), + ComputerNamePrefix: to.Ptr("vmss"), + }, + StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{ + ImageReference: &armcompute.ImageReference{ + Offer: to.Ptr("WindowsServer"), + Publisher: to.Ptr("MicrosoftWindowsServer"), + SKU: to.Ptr("2016-Datacenter"), + Version: to.Ptr("latest"), + }, + OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{ + Caching: to.Ptr(armcompute.CachingTypesReadWrite), + CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage), + ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{ + StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS), + }, + }, + }, + }, + }, + SKU: &armcompute.SKU{ + Name: to.Ptr("Standard_D1_v2"), + Capacity: to.Ptr[int64](3), + Tier: to.Ptr("Standard"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/virtualMachines/{vmName}/runCommands/{runCommandName} +func (testsuite *RunCommandTestSuite) TestVirtualMachineRunCommands() { + var err error + // From step VirtualMachineRunCommands_CreateOrUpdate + fmt.Println("Call operation: VirtualMachineRunCommands_CreateOrUpdate") + virtualMachineRunCommandsClient, err := armcompute.NewVirtualMachineRunCommandsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachineRunCommandsClientCreateOrUpdateResponsePoller, err := virtualMachineRunCommandsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, testsuite.vmRunCommandName, armcompute.VirtualMachineRunCommand{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.VirtualMachineRunCommandProperties{ + AsyncExecution: to.Ptr(false), + Parameters: []*armcompute.RunCommandInputParameter{ + { + Name: to.Ptr("param1"), + Value: to.Ptr("value1"), + }, + { + Name: to.Ptr("param2"), + Value: to.Ptr("value2"), + }}, + RunAsPassword: to.Ptr(""), + RunAsUser: to.Ptr("user1"), + Source: &armcompute.VirtualMachineRunCommandScriptSource{ + Script: to.Ptr("Write-Host Hello World!"), + }, + TimeoutInSeconds: to.Ptr[int32](3600), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineRunCommandsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineRunCommands_List + fmt.Println("Call operation: VirtualMachineRunCommands_List") + virtualMachineRunCommandsClientNewListPager := virtualMachineRunCommandsClient.NewListPager(testsuite.location, nil) + for virtualMachineRunCommandsClientNewListPager.More() { + _, err := virtualMachineRunCommandsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachineRunCommands_Get + fmt.Println("Call operation: VirtualMachineRunCommands_Get") + _, err = virtualMachineRunCommandsClient.Get(testsuite.ctx, testsuite.location, "RunPowerShellScript", nil) + testsuite.Require().NoError(err) + + // From step VirtualMachineRunCommands_ListByVirtualMachine + fmt.Println("Call operation: VirtualMachineRunCommands_ListByVirtualMachine") + virtualMachineRunCommandsClientNewListByVirtualMachinePager := virtualMachineRunCommandsClient.NewListByVirtualMachinePager(testsuite.resourceGroupName, testsuite.vmName, &armcompute.VirtualMachineRunCommandsClientListByVirtualMachineOptions{Expand: nil}) + for virtualMachineRunCommandsClientNewListByVirtualMachinePager.More() { + _, err := virtualMachineRunCommandsClientNewListByVirtualMachinePager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachineRunCommands_GetByVirtualMachine + fmt.Println("Call operation: VirtualMachineRunCommands_GetByVirtualMachine") + _, err = virtualMachineRunCommandsClient.GetByVirtualMachine(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, testsuite.vmRunCommandName, &armcompute.VirtualMachineRunCommandsClientGetByVirtualMachineOptions{Expand: nil}) + testsuite.Require().NoError(err) + + // From step VirtualMachineRunCommands_Update + fmt.Println("Call operation: VirtualMachineRunCommands_Update") + virtualMachineRunCommandsClientUpdateResponsePoller, err := virtualMachineRunCommandsClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, testsuite.vmRunCommandName, armcompute.VirtualMachineRunCommandUpdate{ + Properties: &armcompute.VirtualMachineRunCommandProperties{ + Source: &armcompute.VirtualMachineRunCommandScriptSource{ + Script: to.Ptr("Write-Host Script Source Updated!"), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineRunCommandsClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachines_RunCommand + fmt.Println("Call operation: VirtualMachines_RunCommand") + virtualMachinesClient, err := armcompute.NewVirtualMachinesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachinesClientRunCommandResponsePoller, err := virtualMachinesClient.BeginRunCommand(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, armcompute.RunCommandInput{ + CommandID: to.Ptr("RunPowerShellScript"), + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientRunCommandResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineRunCommands_Delete + fmt.Println("Call operation: VirtualMachineRunCommands_Delete") + virtualMachineRunCommandsClientDeleteResponsePoller, err := virtualMachineRunCommandsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, testsuite.vmRunCommandName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineRunCommandsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/virtualMachines/{instanceId}/runCommands/{runCommandName} +func (testsuite *RunCommandTestSuite) TestVirtualMachineScaleSetVmRunCommands() { + var err error + // From step VirtualMachineScaleSetVMRunCommands_CreateOrUpdate + fmt.Println("Call operation: VirtualMachineScaleSetVMRunCommands_CreateOrUpdate") + virtualMachineScaleSetVMRunCommandsClient, err := armcompute.NewVirtualMachineScaleSetVMRunCommandsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachineScaleSetVMRunCommandsClientCreateOrUpdateResponsePoller, err := virtualMachineScaleSetVMRunCommandsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, "0", testsuite.vmssRunCommandName, armcompute.VirtualMachineRunCommand{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.VirtualMachineRunCommandProperties{ + AsyncExecution: to.Ptr(false), + Parameters: []*armcompute.RunCommandInputParameter{ + { + Name: to.Ptr("param1"), + Value: to.Ptr("value1"), + }, + { + Name: to.Ptr("param2"), + Value: to.Ptr("value2"), + }}, + RunAsPassword: to.Ptr(""), + RunAsUser: to.Ptr("user1"), + Source: &armcompute.VirtualMachineRunCommandScriptSource{ + Script: to.Ptr("Write-Host Hello World!"), + }, + TimeoutInSeconds: to.Ptr[int32](3600), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMRunCommandsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMRunCommands_List + fmt.Println("Call operation: VirtualMachineScaleSetVMRunCommands_List") + virtualMachineScaleSetVMRunCommandsClientNewListPager := virtualMachineScaleSetVMRunCommandsClient.NewListPager(testsuite.resourceGroupName, testsuite.vmScaleSetName, "0", &armcompute.VirtualMachineScaleSetVMRunCommandsClientListOptions{Expand: nil}) + for virtualMachineScaleSetVMRunCommandsClientNewListPager.More() { + _, err := virtualMachineScaleSetVMRunCommandsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachineScaleSetVMRunCommands_Get + fmt.Println("Call operation: VirtualMachineScaleSetVMRunCommands_Get") + _, err = virtualMachineScaleSetVMRunCommandsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, "0", testsuite.vmssRunCommandName, &armcompute.VirtualMachineScaleSetVMRunCommandsClientGetOptions{Expand: nil}) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMRunCommands_Update + fmt.Println("Call operation: VirtualMachineScaleSetVMRunCommands_Update") + virtualMachineScaleSetVMRunCommandsClientUpdateResponsePoller, err := virtualMachineScaleSetVMRunCommandsClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, "0", testsuite.vmssRunCommandName, armcompute.VirtualMachineRunCommandUpdate{ + Properties: &armcompute.VirtualMachineRunCommandProperties{ + Source: &armcompute.VirtualMachineRunCommandScriptSource{ + Script: to.Ptr("Write-Host Script Source Updated!"), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMRunCommandsClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMs_RunCommand + fmt.Println("Call operation: VirtualMachineScaleSetVMs_RunCommand") + virtualMachineScaleSetVMsClient, err := armcompute.NewVirtualMachineScaleSetVMsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachineScaleSetVMsClientRunCommandResponsePoller, err := virtualMachineScaleSetVMsClient.BeginRunCommand(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, "0", armcompute.RunCommandInput{ + CommandID: to.Ptr("RunPowerShellScript"), + Script: []*string{ + to.Ptr("Write-Host Hello World!")}, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMsClientRunCommandResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMRunCommands_Delete + fmt.Println("Call operation: VirtualMachineScaleSetVMRunCommands_Delete") + virtualMachineScaleSetVMRunCommandsClientDeleteResponsePoller, err := virtualMachineScaleSetVMRunCommandsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, "0", testsuite.vmssRunCommandName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMRunCommandsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/skus_live_test.go b/sdk/resourcemanager/compute/armcompute/skus_live_test.go new file mode 100644 index 000000000000..89b12f6ec696 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/skus_live_test.go @@ -0,0 +1,73 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type SkusTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *SkusTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *SkusTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestSkusTestSuite(t *testing.T) { + suite.Run(t, new(SkusTestSuite)) +} + +// Microsoft.Compute/skus +func (testsuite *SkusTestSuite) TestResourceSkus() { + var err error + // From step ResourceSkus_List + fmt.Println("Call operation: ResourceSKUs_List") + resourceSKUsClient, err := armcompute.NewResourceSKUsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + resourceSKUsClientNewListPager := resourceSKUsClient.NewListPager(&armcompute.ResourceSKUsClientListOptions{ + Filter: to.Ptr("location eq 'westus2'"), + }) + for resourceSKUsClientNewListPager.More() { + _, err := resourceSKUsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} diff --git a/sdk/resourcemanager/compute/armcompute/snapshot_live_test.go b/sdk/resourcemanager/compute/armcompute/snapshot_live_test.go new file mode 100644 index 000000000000..e664393005d1 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/snapshot_live_test.go @@ -0,0 +1,141 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type SnapshotTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + snapshotName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *SnapshotTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.snapshotName = testutil.GenerateAlphaNumericID(testsuite.T(), "snapshotna", 6) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *SnapshotTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestSnapshotTestSuite(t *testing.T) { + suite.Run(t, new(SnapshotTestSuite)) +} + +// Microsoft.Compute/snapshots/{snapshotName} +func (testsuite *SnapshotTestSuite) TestSnapshots() { + var err error + // From step Snapshots_CreateOrUpdate + fmt.Println("Call operation: Snapshots_CreateOrUpdate") + snapshotsClient, err := armcompute.NewSnapshotsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + snapshotsClientCreateOrUpdateResponsePoller, err := snapshotsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.snapshotName, armcompute.Snapshot{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.SnapshotProperties{ + CreationData: &armcompute.CreationData{ + CreateOption: to.Ptr(armcompute.DiskCreateOptionEmpty), + }, + DiskSizeGB: to.Ptr[int32](10), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, snapshotsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step Snapshots_List + fmt.Println("Call operation: Snapshots_List") + snapshotsClientNewListPager := snapshotsClient.NewListPager(nil) + for snapshotsClientNewListPager.More() { + _, err := snapshotsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Snapshots_ListByResourceGroup + fmt.Println("Call operation: Snapshots_ListByResourceGroup") + snapshotsClientNewListByResourceGroupPager := snapshotsClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for snapshotsClientNewListByResourceGroupPager.More() { + _, err := snapshotsClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Snapshots_Get + fmt.Println("Call operation: Snapshots_Get") + _, err = snapshotsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.snapshotName, nil) + testsuite.Require().NoError(err) + + // From step Snapshots_Update + fmt.Println("Call operation: Snapshots_Update") + snapshotsClientUpdateResponsePoller, err := snapshotsClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.snapshotName, armcompute.SnapshotUpdate{ + Properties: &armcompute.SnapshotUpdateProperties{ + DiskSizeGB: to.Ptr[int32](20), + }, + Tags: map[string]*string{ + "department": to.Ptr("Development"), + "project": to.Ptr("UpdateSnapshots"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, snapshotsClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step Snapshots_GrantAccess + fmt.Println("Call operation: Snapshots_GrantAccess") + snapshotsClientGrantAccessResponsePoller, err := snapshotsClient.BeginGrantAccess(testsuite.ctx, testsuite.resourceGroupName, testsuite.snapshotName, armcompute.GrantAccessData{ + Access: to.Ptr(armcompute.AccessLevelRead), + DurationInSeconds: to.Ptr[int32](300), + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, snapshotsClientGrantAccessResponsePoller) + testsuite.Require().NoError(err) + + // From step Snapshots_RevokeAccess + fmt.Println("Call operation: Snapshots_RevokeAccess") + snapshotsClientRevokeAccessResponsePoller, err := snapshotsClient.BeginRevokeAccess(testsuite.ctx, testsuite.resourceGroupName, testsuite.snapshotName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, snapshotsClientRevokeAccessResponsePoller) + testsuite.Require().NoError(err) + + // From step Snapshots_Delete + fmt.Println("Call operation: Snapshots_Delete") + snapshotsClientDeleteResponsePoller, err := snapshotsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.snapshotName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, snapshotsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/sshpublickey_live_test.go b/sdk/resourcemanager/compute/armcompute/sshpublickey_live_test.go new file mode 100644 index 000000000000..3b5dc535b395 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/sshpublickey_live_test.go @@ -0,0 +1,113 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type SshPublicKeyTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + sshPublicKeyName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *SshPublicKeyTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.sshPublicKeyName = testutil.GenerateAlphaNumericID(testsuite.T(), "sshpublick", 6) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *SshPublicKeyTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestSshPublicKeyTestSuite(t *testing.T) { + suite.Run(t, new(SshPublicKeyTestSuite)) +} + +// Microsoft.Compute/sshPublicKeys/{sshPublicKeyName} +func (testsuite *SshPublicKeyTestSuite) TestSshPublicKeys() { + var err error + // From step SshPublicKeys_Create + fmt.Println("Call operation: SSHPublicKeys_Create") + sSHPublicKeysClient, err := armcompute.NewSSHPublicKeysClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = sSHPublicKeysClient.Create(testsuite.ctx, testsuite.resourceGroupName, testsuite.sshPublicKeyName, armcompute.SSHPublicKeyResource{ + Location: to.Ptr(testsuite.location), + }, nil) + testsuite.Require().NoError(err) + + // From step SshPublicKeys_ListBySubscription + fmt.Println("Call operation: SSHPublicKeys_ListBySubscription") + sSHPublicKeysClientNewListBySubscriptionPager := sSHPublicKeysClient.NewListBySubscriptionPager(nil) + for sSHPublicKeysClientNewListBySubscriptionPager.More() { + _, err := sSHPublicKeysClientNewListBySubscriptionPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step SshPublicKeys_ListByResourceGroup + fmt.Println("Call operation: SSHPublicKeys_ListByResourceGroup") + sSHPublicKeysClientNewListByResourceGroupPager := sSHPublicKeysClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for sSHPublicKeysClientNewListByResourceGroupPager.More() { + _, err := sSHPublicKeysClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step SshPublicKeys_Get + fmt.Println("Call operation: SSHPublicKeys_Get") + _, err = sSHPublicKeysClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.sshPublicKeyName, nil) + testsuite.Require().NoError(err) + + // From step SshPublicKeys_Update + fmt.Println("Call operation: SSHPublicKeys_Update") + _, err = sSHPublicKeysClient.Update(testsuite.ctx, testsuite.resourceGroupName, testsuite.sshPublicKeyName, armcompute.SSHPublicKeyUpdateResource{ + Tags: map[string]*string{ + "key2854": to.Ptr("a"), + }, + }, nil) + testsuite.Require().NoError(err) + + // From step SshPublicKeys_GenerateKeyPair + fmt.Println("Call operation: SSHPublicKeys_GenerateKeyPair") + _, err = sSHPublicKeysClient.GenerateKeyPair(testsuite.ctx, testsuite.resourceGroupName, testsuite.sshPublicKeyName, nil) + testsuite.Require().NoError(err) + + // From step SshPublicKeys_Delete + fmt.Println("Call operation: SSHPublicKeys_Delete") + _, err = sSHPublicKeysClient.Delete(testsuite.ctx, testsuite.resourceGroupName, testsuite.sshPublicKeyName, nil) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachine_live_test.go b/sdk/resourcemanager/compute/armcompute/virtualmachine_live_test.go new file mode 100644 index 000000000000..987606b16747 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/virtualmachine_live_test.go @@ -0,0 +1,348 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/stretchr/testify/suite" +) + +type VirtualMachineTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + adminUsername string + networkInterfaceId string + networkInterfaceName string + virtualNetworksName string + vmName string + adminPassword string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *VirtualMachineTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.adminUsername = testutil.GenerateAlphaNumericID(testsuite.T(), "vmuserna", 6) + testsuite.networkInterfaceName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmnic", 6) + testsuite.virtualNetworksName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmvnet", 6) + testsuite.vmName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmname", 6) + testsuite.adminPassword = testutil.GetEnv("ADMIN_PASSWORD", "") + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *VirtualMachineTestSuite) TearDownSuite() { + testsuite.Cleanup() + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestVirtualMachineTestSuite(t *testing.T) { + suite.Run(t, new(VirtualMachineTestSuite)) +} + +func (testsuite *VirtualMachineTestSuite) Prepare() { + var err error + // From step Create_NetworkInterface + template := map[string]any{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "outputs": map[string]any{ + "networkInterfaceId": map[string]any{ + "type": "string", + "value": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]", + }, + }, + "parameters": map[string]any{ + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "networkInterfaceName": map[string]any{ + "type": "string", + "defaultValue": testsuite.networkInterfaceName, + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": testsuite.virtualNetworksName, + }, + }, + "resources": []any{ + map[string]any{ + "name": "[parameters('virtualNetworksName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2021-05-01", + "location": "[parameters('location')]", + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ + "10.0.0.0/16", + }, + }, + "subnets": []any{ + map[string]any{ + "name": "default", + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + }, + }, + }, + }, + }, + map[string]any{ + "name": "[parameters('networkInterfaceName')]", + "type": "Microsoft.Network/networkInterfaces", + "apiVersion": "2021-08-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworksName'))]", + }, + "location": "[parameters('location')]", + "properties": map[string]any{ + "ipConfigurations": []any{ + map[string]any{ + "name": "Ipv4config", + "properties": map[string]any{ + "subnet": map[string]any{ + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + }, + }, + }, + }, + }, + }, + } + deployment := armresources.Deployment{ + Properties: &armresources.DeploymentProperties{ + Template: template, + Mode: to.Ptr(armresources.DeploymentModeIncremental), + }, + } + deploymentExtend, err := testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_NetworkInterface", &deployment) + testsuite.Require().NoError(err) + testsuite.networkInterfaceId = deploymentExtend.Properties.Outputs.(map[string]interface{})["networkInterfaceId"].(map[string]interface{})["value"].(string) + + // From step VirtualMachines_CreateOrUpdate + fmt.Println("Call operation: VirtualMachines_CreateOrUpdate") + virtualMachinesClient, err := armcompute.NewVirtualMachinesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachinesClientCreateOrUpdateResponsePoller, err := virtualMachinesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, armcompute.VirtualMachine{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.VirtualMachineProperties{ + HardwareProfile: &armcompute.HardwareProfile{ + VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardD1V2), + }, + NetworkProfile: &armcompute.NetworkProfile{ + NetworkInterfaces: []*armcompute.NetworkInterfaceReference{ + { + ID: to.Ptr(testsuite.networkInterfaceId), + Properties: &armcompute.NetworkInterfaceReferenceProperties{ + Primary: to.Ptr(true), + }, + }}, + }, + OSProfile: &armcompute.OSProfile{ + AdminPassword: to.Ptr(testsuite.adminPassword), + AdminUsername: to.Ptr(testsuite.adminUsername), + ComputerName: to.Ptr(testsuite.vmName), + }, + StorageProfile: &armcompute.StorageProfile{ + ImageReference: &armcompute.ImageReference{ + Offer: to.Ptr("WindowsServer"), + Publisher: to.Ptr("MicrosoftWindowsServer"), + SKU: to.Ptr("2016-Datacenter"), + Version: to.Ptr("latest"), + }, + OSDisk: &armcompute.OSDisk{ + Name: to.Ptr(testsuite.vmName + "osdisk"), + Caching: to.Ptr(armcompute.CachingTypesReadWrite), + CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage), + ManagedDisk: &armcompute.ManagedDiskParameters{ + StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS), + }, + }, + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/virtualMachines/{vmName} +func (testsuite *VirtualMachineTestSuite) TestVirtualMachines() { + var err error + // From step VirtualMachines_ListByLocation + fmt.Println("Call operation: VirtualMachines_ListByLocation") + virtualMachinesClient, err := armcompute.NewVirtualMachinesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachinesClientNewListByLocationPager := virtualMachinesClient.NewListByLocationPager(testsuite.location, nil) + for virtualMachinesClientNewListByLocationPager.More() { + _, err := virtualMachinesClientNewListByLocationPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachines_InstanceView + fmt.Println("Call operation: VirtualMachines_InstanceView") + _, err = virtualMachinesClient.InstanceView(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, nil) + testsuite.Require().NoError(err) + + // From step VirtualMachines_ListAll + fmt.Println("Call operation: VirtualMachines_ListAll") + virtualMachinesClientNewListAllPager := virtualMachinesClient.NewListAllPager(&armcompute.VirtualMachinesClientListAllOptions{StatusOnly: nil, + Filter: nil, + }) + for virtualMachinesClientNewListAllPager.More() { + _, err := virtualMachinesClientNewListAllPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachines_List + fmt.Println("Call operation: VirtualMachines_List") + virtualMachinesClientNewListPager := virtualMachinesClient.NewListPager(testsuite.resourceGroupName, &armcompute.VirtualMachinesClientListOptions{Filter: nil}) + for virtualMachinesClientNewListPager.More() { + _, err := virtualMachinesClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachines_Get + fmt.Println("Call operation: VirtualMachines_Get") + _, err = virtualMachinesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, &armcompute.VirtualMachinesClientGetOptions{Expand: to.Ptr(armcompute.InstanceViewTypesUserData)}) + testsuite.Require().NoError(err) + + // From step VirtualMachines_ListAvailableSizes + fmt.Println("Call operation: VirtualMachines_ListAvailableSizes") + virtualMachinesClientNewListAvailableSizesPager := virtualMachinesClient.NewListAvailableSizesPager(testsuite.resourceGroupName, testsuite.vmName, nil) + for virtualMachinesClientNewListAvailableSizesPager.More() { + _, err := virtualMachinesClientNewListAvailableSizesPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachines_Update + fmt.Println("Call operation: VirtualMachines_Update") + virtualMachinesClientUpdateResponsePoller, err := virtualMachinesClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, armcompute.VirtualMachineUpdate{ + Tags: map[string]*string{ + "virtaulMachine": to.Ptr("vmupdate"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachines_InstallPatches + fmt.Println("Call operation: VirtualMachines_InstallPatches") + virtualMachinesClientInstallPatchesResponsePoller, err := virtualMachinesClient.BeginInstallPatches(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, armcompute.VirtualMachineInstallPatchesParameters{ + MaximumDuration: to.Ptr("PT4H"), + RebootSetting: to.Ptr(armcompute.VMGuestPatchRebootSettingIfRequired), + WindowsParameters: &armcompute.WindowsParameters{ + ClassificationsToInclude: []*armcompute.VMGuestPatchClassificationWindows{ + to.Ptr(armcompute.VMGuestPatchClassificationWindowsCritical), + to.Ptr(armcompute.VMGuestPatchClassificationWindowsSecurity)}, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientInstallPatchesResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachines_Deallocate + fmt.Println("Call operation: VirtualMachines_Deallocate") + virtualMachinesClientDeallocateResponsePoller, err := virtualMachinesClient.BeginDeallocate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, &armcompute.VirtualMachinesClientBeginDeallocateOptions{Hibernate: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientDeallocateResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachines_Start + fmt.Println("Call operation: VirtualMachines_Start") + virtualMachinesClientStartResponsePoller, err := virtualMachinesClient.BeginStart(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientStartResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachines_AssessPatches + fmt.Println("Call operation: VirtualMachines_AssessPatches") + virtualMachinesClientAssessPatchesResponsePoller, err := virtualMachinesClient.BeginAssessPatches(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientAssessPatchesResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachines_Restart + fmt.Println("Call operation: VirtualMachines_Restart") + virtualMachinesClientRestartResponsePoller, err := virtualMachinesClient.BeginRestart(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientRestartResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachines_Reapply + fmt.Println("Call operation: VirtualMachines_Reapply") + virtualMachinesClientReapplyResponsePoller, err := virtualMachinesClient.BeginReapply(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientReapplyResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachines_RunCommand + fmt.Println("Call operation: VirtualMachines_RunCommand") + virtualMachinesClientRunCommandResponsePoller, err := virtualMachinesClient.BeginRunCommand(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, armcompute.RunCommandInput{ + CommandID: to.Ptr("RunPowerShellScript"), + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientRunCommandResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachines_Redeploy + fmt.Println("Call operation: VirtualMachines_Redeploy") + virtualMachinesClientRedeployResponsePoller, err := virtualMachinesClient.BeginRedeploy(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientRedeployResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachines_PowerOff + fmt.Println("Call operation: VirtualMachines_PowerOff") + virtualMachinesClientPowerOffResponsePoller, err := virtualMachinesClient.BeginPowerOff(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, &armcompute.VirtualMachinesClientBeginPowerOffOptions{SkipShutdown: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientPowerOffResponsePoller) + testsuite.Require().NoError(err) +} + +func (testsuite *VirtualMachineTestSuite) Cleanup() { + var err error + // From step VirtualMachines_Delete + fmt.Println("Call operation: VirtualMachines_Delete") + virtualMachinesClient, err := armcompute.NewVirtualMachinesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachinesClientDeleteResponsePoller, err := virtualMachinesClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmName, &armcompute.VirtualMachinesClientBeginDeleteOptions{ForceDeletion: to.Ptr(true)}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachinesClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachineextensionimage_live_test.go b/sdk/resourcemanager/compute/armcompute/virtualmachineextensionimage_live_test.go new file mode 100644 index 000000000000..c67c58321675 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/virtualmachineextensionimage_live_test.go @@ -0,0 +1,82 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type VirtualMachineExtensionImageTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *VirtualMachineExtensionImageTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *VirtualMachineExtensionImageTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestVirtualMachineExtensionImageTestSuite(t *testing.T) { + suite.Run(t, new(VirtualMachineExtensionImageTestSuite)) +} + +// Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmextension/types +func (testsuite *VirtualMachineExtensionImageTestSuite) TestVirtualMachineExtensionImages() { + publisherName := "Microsoft.Compute" + typeParam := "CustomScriptExtension" + version := "1.9" + var err error + // From step VirtualMachineExtensionImages_ListTypes + fmt.Println("Call operation: VirtualMachineExtensionImages_ListTypes") + virtualMachineExtensionImagesClient, err := armcompute.NewVirtualMachineExtensionImagesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = virtualMachineExtensionImagesClient.ListTypes(testsuite.ctx, testsuite.location, publisherName, nil) + testsuite.Require().NoError(err) + + // From step VirtualMachineExtensionImages_ListVersions + fmt.Println("Call operation: VirtualMachineExtensionImages_ListVersions") + _, err = virtualMachineExtensionImagesClient.ListVersions(testsuite.ctx, testsuite.location, publisherName, typeParam, &armcompute.VirtualMachineExtensionImagesClientListVersionsOptions{Filter: nil, + Top: nil, + Orderby: nil, + }) + testsuite.Require().NoError(err) + + // From step VirtualMachineExtensionImages_Get + fmt.Println("Call operation: VirtualMachineExtensionImages_Get") + _, err = virtualMachineExtensionImagesClient.Get(testsuite.ctx, testsuite.location, publisherName, typeParam, version, nil) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachineimage_live_test.go b/sdk/resourcemanager/compute/armcompute/virtualmachineimage_live_test.go new file mode 100644 index 000000000000..8d2d799af082 --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/virtualmachineimage_live_test.go @@ -0,0 +1,93 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type VirtualMachineImageTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *VirtualMachineImageTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *VirtualMachineImageTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestVirtualMachineImageTestSuite(t *testing.T) { + suite.Run(t, new(VirtualMachineImageTestSuite)) +} + +// Microsoft.Compute/locations/publishers +func (testsuite *VirtualMachineImageTestSuite) TestVirtualMachineImages() { + offer := "office-365" + publisherName := "MicrosoftWindowsDesktop" + skus := "win11-22h2-avd-m365" + version := "22621.1105.230110" + var err error + // From step VirtualMachineImages_ListPublishers + fmt.Println("Call operation: VirtualMachineImages_ListPublishers") + virtualMachineImagesClient, err := armcompute.NewVirtualMachineImagesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = virtualMachineImagesClient.ListPublishers(testsuite.ctx, testsuite.location, nil) + testsuite.Require().NoError(err) + + // From step VirtualMachineImages_ListOffers + fmt.Println("Call operation: VirtualMachineImages_ListOffers") + _, err = virtualMachineImagesClient.ListOffers(testsuite.ctx, testsuite.location, publisherName, nil) + testsuite.Require().NoError(err) + + // From step VirtualMachineImages_ListSkus + fmt.Println("Call operation: VirtualMachineImages_ListSKUs") + _, err = virtualMachineImagesClient.ListSKUs(testsuite.ctx, testsuite.location, publisherName, offer, nil) + testsuite.Require().NoError(err) + + // From step VirtualMachineImages_List + fmt.Println("Call operation: VirtualMachineImages_List") + _, err = virtualMachineImagesClient.List(testsuite.ctx, testsuite.location, publisherName, offer, skus, &armcompute.VirtualMachineImagesClientListOptions{Expand: nil, + Top: nil, + Orderby: nil, + }) + testsuite.Require().NoError(err) + + // From step VirtualMachineImages_Get + fmt.Println("Call operation: VirtualMachineImages_Get") + _, err = virtualMachineImagesClient.Get(testsuite.ctx, testsuite.location, publisherName, offer, skus, version, nil) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachines_client_live_test.go b/sdk/resourcemanager/compute/armcompute/virtualmachines_client_live_test.go deleted file mode 100644 index 01d54b7ab595..000000000000 --- a/sdk/resourcemanager/compute/armcompute/virtualmachines_client_live_test.go +++ /dev/null @@ -1,312 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -package armcompute_test - -import ( - "context" - "fmt" - "testing" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" - "github.com/stretchr/testify/suite" -) - -type VirtualMachinesClientTestSuite struct { - suite.Suite - - ctx context.Context - cred azcore.TokenCredential - options *arm.ClientOptions - location string - resourceGroupName string - subscriptionID string -} - -func (testsuite *VirtualMachinesClientTestSuite) SetupSuite() { - testsuite.ctx = context.Background() - testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") - testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") - resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) - testsuite.Require().NoError(err) - testsuite.resourceGroupName = *resourceGroup.Name -} - -func (testsuite *VirtualMachinesClientTestSuite) TearDownSuite() { - _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.resourceGroupName) - testsuite.Require().NoError(err) - testutil.StopRecording(testsuite.T()) -} - -func TestVirtualMachinesClient(t *testing.T) { - suite.Run(t, new(VirtualMachinesClientTestSuite)) -} - -func (testsuite *VirtualMachinesClientTestSuite) TestVirtualMachineCRUD() { - // create virtual network - vnClient, err := armnetwork.NewVirtualNetworksClient(testsuite.subscriptionID, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - vnName := "go-test-network" - vnPoller, err := vnClient.BeginCreateOrUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - vnName, - armnetwork.VirtualNetwork{ - Location: to.Ptr(testsuite.location), - Properties: &armnetwork.VirtualNetworkPropertiesFormat{ - AddressSpace: &armnetwork.AddressSpace{ - AddressPrefixes: []*string{ - to.Ptr("10.1.0.0/16"), - }, - }, - }, - }, - nil, - ) - testsuite.Require().NoError(err) - vnResp, err := testutil.PollForTest(testsuite.ctx, vnPoller) - testsuite.Require().NoError(err) - testsuite.Require().Equal(*vnResp.Name, vnName) - - // create subnet - subClient, err := armnetwork.NewSubnetsClient(testsuite.subscriptionID, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - subName := "go-test-subnet" - subPoller, err := subClient.BeginCreateOrUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - vnName, - subName, - armnetwork.Subnet{ - Properties: &armnetwork.SubnetPropertiesFormat{ - AddressPrefix: to.Ptr("10.1.10.0/24"), - }, - }, - nil, - ) - testsuite.Require().NoError(err) - subResp, err := testutil.PollForTest(testsuite.ctx, subPoller) - testsuite.Require().NoError(err) - subnetID := *subResp.ID - testsuite.Require().Equal(*subResp.Name, subName) - - // create public ip address - ipClient, err := armnetwork.NewPublicIPAddressesClient(testsuite.subscriptionID, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - ipName := "go-test-ip" - testsuite.Require().NoError(err) - ipPoller, err := ipClient.BeginCreateOrUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - ipName, - armnetwork.PublicIPAddress{ - Location: to.Ptr(testsuite.location), - Properties: &armnetwork.PublicIPAddressPropertiesFormat{ - PublicIPAllocationMethod: to.Ptr(armnetwork.IPAllocationMethodStatic), // Static or Dynamic - }, - }, - nil, - ) - testsuite.Require().NoError(err) - ipResp, err := testutil.PollForTest(testsuite.ctx, ipPoller) - testsuite.Require().NoError(err) - publicIPAddressID := *ipResp.ID - testsuite.Require().Equal(*ipResp.Name, ipName) - - // create network security group - nsgClient, err := armnetwork.NewSecurityGroupsClient(testsuite.subscriptionID, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - nsgName := "go-test-nsg" - testsuite.Require().NoError(err) - nsgPoller, err := nsgClient.BeginCreateOrUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - nsgName, - armnetwork.SecurityGroup{ - Location: to.Ptr(testsuite.location), - Properties: &armnetwork.SecurityGroupPropertiesFormat{ - SecurityRules: []*armnetwork.SecurityRule{ - { - Name: to.Ptr("sample_inbound_22"), - Properties: &armnetwork.SecurityRulePropertiesFormat{ - SourceAddressPrefix: to.Ptr("0.0.0.0/0"), - SourcePortRange: to.Ptr("*"), - DestinationAddressPrefix: to.Ptr("0.0.0.0/0"), - DestinationPortRange: to.Ptr("22"), - Protocol: to.Ptr(armnetwork.SecurityRuleProtocolTCP), - Access: to.Ptr(armnetwork.SecurityRuleAccessAllow), - Priority: to.Ptr[int32](100), - Description: to.Ptr("sample network security group inbound port 22"), - Direction: to.Ptr(armnetwork.SecurityRuleDirectionInbound), - }, - }, - // outbound - { - Name: to.Ptr("sample_outbound_22"), - Properties: &armnetwork.SecurityRulePropertiesFormat{ - SourceAddressPrefix: to.Ptr("0.0.0.0/0"), - SourcePortRange: to.Ptr("*"), - DestinationAddressPrefix: to.Ptr("0.0.0.0/0"), - DestinationPortRange: to.Ptr("22"), - Protocol: to.Ptr(armnetwork.SecurityRuleProtocolTCP), - Access: to.Ptr(armnetwork.SecurityRuleAccessAllow), - Priority: to.Ptr[int32](100), - Description: to.Ptr("sample network security group outbound port 22"), - Direction: to.Ptr(armnetwork.SecurityRuleDirectionOutbound), - }, - }, - }, - }, - }, - nil, - ) - testsuite.Require().NoError(err) - nsgResp, err := testutil.PollForTest(testsuite.ctx, nsgPoller) - testsuite.Require().NoError(err) - networkSecurityGroupID := *nsgResp.ID - testsuite.Require().Equal(*nsgResp.Name, nsgName) - - // create network interface - nicClient, err := armnetwork.NewInterfacesClient(testsuite.subscriptionID, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - nicName := "go-test-nic" - testsuite.Require().NoError(err) - nicPoller, err := nicClient.BeginCreateOrUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - nicName, - armnetwork.Interface{ - Location: to.Ptr(testsuite.location), - Properties: &armnetwork.InterfacePropertiesFormat{ - //NetworkSecurityGroup: - IPConfigurations: []*armnetwork.InterfaceIPConfiguration{ - { - Name: to.Ptr("ipConfig"), - Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{ - PrivateIPAllocationMethod: to.Ptr(armnetwork.IPAllocationMethodDynamic), - Subnet: &armnetwork.Subnet{ - ID: to.Ptr(subnetID), - }, - PublicIPAddress: &armnetwork.PublicIPAddress{ - ID: to.Ptr(publicIPAddressID), - }, - }, - }, - }, - NetworkSecurityGroup: &armnetwork.SecurityGroup{ - ID: to.Ptr(networkSecurityGroupID), - }, - }, - }, - nil, - ) - testsuite.Require().NoError(err) - nicResp, err := testutil.PollForTest(testsuite.ctx, nicPoller) - testsuite.Require().NoError(err) - networkInterfaceID := *nicResp.ID - testsuite.Require().Equal(*nicResp.Name, nicName) - - // create virtual machine - fmt.Println("Call operation: VirtualMachines_CreateOrUpdate") - vmClient, err := armcompute.NewVirtualMachinesClient(testsuite.subscriptionID, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - vmName := "go-test-vm" - testsuite.Require().NoError(err) - diskName := "go-test-disk" - testsuite.Require().NoError(err) - vmPoller, err := vmClient.BeginCreateOrUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - vmName, - armcompute.VirtualMachine{ - Location: to.Ptr(testsuite.location), - Identity: &armcompute.VirtualMachineIdentity{ - Type: to.Ptr(armcompute.ResourceIdentityTypeNone), - }, - Properties: &armcompute.VirtualMachineProperties{ - StorageProfile: &armcompute.StorageProfile{ - ImageReference: &armcompute.ImageReference{ - Offer: to.Ptr("WindowsServer"), - Publisher: to.Ptr("MicrosoftWindowsServer"), - SKU: to.Ptr("2019-Datacenter"), - Version: to.Ptr("latest"), - }, - OSDisk: &armcompute.OSDisk{ - Name: to.Ptr(diskName), - CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage), - Caching: to.Ptr(armcompute.CachingTypesReadWrite), - ManagedDisk: &armcompute.ManagedDiskParameters{ - StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS), // OSDisk type Standard/Premium HDD/SSD - }, - }, - }, - HardwareProfile: &armcompute.HardwareProfile{ - VMSize: to.Ptr(armcompute.VirtualMachineSizeTypesStandardF2S), // VM size include vCPUs,RAM,Data Disks,Temp storage. - }, - OSProfile: &armcompute.OSProfile{ - ComputerName: to.Ptr("sample-compute"), - AdminUsername: to.Ptr("sample-user"), - AdminPassword: to.Ptr("Password01!@#"), - }, - NetworkProfile: &armcompute.NetworkProfile{ - NetworkInterfaces: []*armcompute.NetworkInterfaceReference{ - { - ID: to.Ptr(networkInterfaceID), - }, - }, - }, - }, - }, - nil, - ) - testsuite.Require().NoError(err) - vmResp, err := testutil.PollForTest(testsuite.ctx, vmPoller) - testsuite.Require().NoError(err) - testsuite.Require().Equal(*vmResp.Name, vmName) - - // virtual machine update - fmt.Println("Call operation: VirtualMachines_Update") - updatePoller, err := vmClient.BeginUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - vmName, - armcompute.VirtualMachineUpdate{ - Tags: map[string]*string{ - "tag": to.Ptr("value"), - }, - }, - nil, - ) - testsuite.Require().NoError(err) - updateResp, err := testutil.PollForTest(testsuite.ctx, updatePoller) - testsuite.Require().NoError(err) - testsuite.Require().Equal(*updateResp.Name, vmName) - - // virtual machine get - fmt.Println("Call operation: VirtualMachines_Get") - resp, err := vmClient.Get(testsuite.ctx, testsuite.resourceGroupName, vmName, nil) - testsuite.Require().NoError(err) - testsuite.Require().Equal(*resp.Name, vmName) - - // virtual machine list - fmt.Println("Call operation: VirtualMachines_List") - vmList := vmClient.NewListPager(testsuite.resourceGroupName, nil) - testsuite.Require().Equal(vmList.More(), true) - - // delete virtual machine - fmt.Println("Call operation: VirtualMachines_Delete") - delPoller, err := vmClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, vmName, nil) - testsuite.Require().NoError(err) - _, err = testutil.PollForTest(testsuite.ctx, delPoller) - testsuite.Require().NoError(err) -} diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachinescaleset_live_test.go b/sdk/resourcemanager/compute/armcompute/virtualmachinescaleset_live_test.go new file mode 100644 index 000000000000..d2e907027f7f --- /dev/null +++ b/sdk/resourcemanager/compute/armcompute/virtualmachinescaleset_live_test.go @@ -0,0 +1,399 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcompute_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/stretchr/testify/suite" +) + +type VirtualMachineScaleSetTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + adminUsername string + subnetId string + virtualNetworkSubnetName string + vmScaleSetName string + vmssExtensionName string + adminPassword string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *VirtualMachineScaleSetTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.adminUsername = testutil.GenerateAlphaNumericID(testsuite.T(), "vmuserna", 6) + testsuite.virtualNetworkSubnetName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmssvnetna", 6) + testsuite.vmScaleSetName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmscaleset", 6) + testsuite.vmssExtensionName = testutil.GenerateAlphaNumericID(testsuite.T(), "vmssextens", 6) + testsuite.adminPassword = testutil.GetEnv("ADMIN_PASSWORD", "") + testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *VirtualMachineScaleSetTestSuite) TearDownSuite() { + testsuite.Cleanup() + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestVirtualMachineScaleSetTestSuite(t *testing.T) { + suite.Run(t, new(VirtualMachineScaleSetTestSuite)) +} + +func (testsuite *VirtualMachineScaleSetTestSuite) Prepare() { + var err error + // From step Create_NetworkAndSubnet + template := map[string]any{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "outputs": map[string]any{ + "subnetId": map[string]any{ + "type": "string", + "value": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkSubnetName'), 'default')]", + }, + }, + "parameters": map[string]any{ + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "virtualNetworkSubnetName": map[string]any{ + "type": "string", + "defaultValue": testsuite.virtualNetworkSubnetName, + }, + }, + "resources": []any{ + map[string]any{ + "name": "[parameters('virtualNetworkSubnetName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2021-05-01", + "location": "[parameters('location')]", + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ + "10.0.0.0/16", + }, + }, + "subnets": []any{ + map[string]any{ + "name": "default", + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + }, + }, + }, + }, + }, + }, + } + deployment := armresources.Deployment{ + Properties: &armresources.DeploymentProperties{ + Template: template, + Mode: to.Ptr(armresources.DeploymentModeIncremental), + }, + } + deploymentExtend, err := testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_NetworkAndSubnet", &deployment) + testsuite.Require().NoError(err) + testsuite.subnetId = deploymentExtend.Properties.Outputs.(map[string]interface{})["subnetId"].(map[string]interface{})["value"].(string) + + // From step VirtualMachineScaleSets_CreateOrUpdate + fmt.Println("Call operation: VirtualMachineScaleSets_CreateOrUpdate") + virtualMachineScaleSetsClient, err := armcompute.NewVirtualMachineScaleSetsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachineScaleSetsClientCreateOrUpdateResponsePoller, err := virtualMachineScaleSetsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, armcompute.VirtualMachineScaleSet{ + Location: to.Ptr(testsuite.location), + Properties: &armcompute.VirtualMachineScaleSetProperties{ + Overprovision: to.Ptr(true), + UpgradePolicy: &armcompute.UpgradePolicy{ + Mode: to.Ptr(armcompute.UpgradeModeManual), + }, + VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{ + NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{ + NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{ + { + Name: to.Ptr(testsuite.vmScaleSetName), + Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{ + EnableIPForwarding: to.Ptr(true), + IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{ + { + Name: to.Ptr(testsuite.vmScaleSetName), + Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{ + Subnet: &armcompute.APIEntityReference{ + ID: to.Ptr(testsuite.subnetId), + }, + }, + }}, + Primary: to.Ptr(true), + }, + }}, + }, + OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{ + AdminPassword: to.Ptr(testsuite.adminPassword), + AdminUsername: to.Ptr(testsuite.adminUsername), + ComputerNamePrefix: to.Ptr("vmss"), + }, + StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{ + ImageReference: &armcompute.ImageReference{ + Offer: to.Ptr("WindowsServer"), + Publisher: to.Ptr("MicrosoftWindowsServer"), + SKU: to.Ptr("2016-Datacenter"), + Version: to.Ptr("latest"), + }, + OSDisk: &armcompute.VirtualMachineScaleSetOSDisk{ + Caching: to.Ptr(armcompute.CachingTypesReadWrite), + CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage), + ManagedDisk: &armcompute.VirtualMachineScaleSetManagedDiskParameters{ + StorageAccountType: to.Ptr(armcompute.StorageAccountTypesStandardLRS), + }, + }, + }, + }, + }, + SKU: &armcompute.SKU{ + Name: to.Ptr("Standard_D1_v2"), + Capacity: to.Ptr[int64](3), + Tier: to.Ptr("Standard"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName} +func (testsuite *VirtualMachineScaleSetTestSuite) TestVirtualMachineScaleSets() { + var err error + // From step VirtualMachineScaleSets_ListByLocation + fmt.Println("Call operation: VirtualMachineScaleSets_ListByLocation") + virtualMachineScaleSetsClient, err := armcompute.NewVirtualMachineScaleSetsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachineScaleSetsClientNewListByLocationPager := virtualMachineScaleSetsClient.NewListByLocationPager(testsuite.location, nil) + for virtualMachineScaleSetsClientNewListByLocationPager.More() { + _, err := virtualMachineScaleSetsClientNewListByLocationPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachineScaleSets_GetInstanceView + fmt.Println("Call operation: VirtualMachineScaleSets_GetInstanceView") + _, err = virtualMachineScaleSetsClient.GetInstanceView(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, nil) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSets_GetOSUpgradeHistory + fmt.Println("Call operation: VirtualMachineScaleSets_GetOSUpgradeHistory") + virtualMachineScaleSetsClientNewGetOSUpgradeHistoryPager := virtualMachineScaleSetsClient.NewGetOSUpgradeHistoryPager(testsuite.resourceGroupName, testsuite.vmScaleSetName, nil) + for virtualMachineScaleSetsClientNewGetOSUpgradeHistoryPager.More() { + _, err := virtualMachineScaleSetsClientNewGetOSUpgradeHistoryPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachineScaleSets_ListAll + fmt.Println("Call operation: VirtualMachineScaleSets_ListAll") + virtualMachineScaleSetsClientNewListAllPager := virtualMachineScaleSetsClient.NewListAllPager(nil) + for virtualMachineScaleSetsClientNewListAllPager.More() { + _, err := virtualMachineScaleSetsClientNewListAllPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachineScaleSets_Get + fmt.Println("Call operation: VirtualMachineScaleSets_Get") + _, err = virtualMachineScaleSetsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, &armcompute.VirtualMachineScaleSetsClientGetOptions{Expand: nil}) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSets_List + fmt.Println("Call operation: VirtualMachineScaleSets_List") + virtualMachineScaleSetsClientNewListPager := virtualMachineScaleSetsClient.NewListPager(testsuite.resourceGroupName, nil) + for virtualMachineScaleSetsClientNewListPager.More() { + _, err := virtualMachineScaleSetsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachineScaleSets_ListSkus + fmt.Println("Call operation: VirtualMachineScaleSets_ListSKUs") + virtualMachineScaleSetsClientNewListSKUsPager := virtualMachineScaleSetsClient.NewListSKUsPager(testsuite.resourceGroupName, testsuite.vmScaleSetName, nil) + for virtualMachineScaleSetsClientNewListSKUsPager.More() { + _, err := virtualMachineScaleSetsClientNewListSKUsPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachineScaleSets_Update + fmt.Println("Call operation: VirtualMachineScaleSets_Update") + virtualMachineScaleSetsClientUpdateResponsePoller, err := virtualMachineScaleSetsClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, armcompute.VirtualMachineScaleSetUpdate{}, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSets_Redeploy + fmt.Println("Call operation: VirtualMachineScaleSets_Redeploy") + virtualMachineScaleSetsClientRedeployResponsePoller, err := virtualMachineScaleSetsClient.BeginRedeploy(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, &armcompute.VirtualMachineScaleSetsClientBeginRedeployOptions{VMInstanceIDs: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientRedeployResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSets_Deallocate + fmt.Println("Call operation: VirtualMachineScaleSets_Deallocate") + virtualMachineScaleSetsClientDeallocateResponsePoller, err := virtualMachineScaleSetsClient.BeginDeallocate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, &armcompute.VirtualMachineScaleSetsClientBeginDeallocateOptions{VMInstanceIDs: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientDeallocateResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSets_Start + fmt.Println("Call operation: VirtualMachineScaleSets_Start") + virtualMachineScaleSetsClientStartResponsePoller, err := virtualMachineScaleSetsClient.BeginStart(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, &armcompute.VirtualMachineScaleSetsClientBeginStartOptions{VMInstanceIDs: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientStartResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSets_Reimage + fmt.Println("Call operation: VirtualMachineScaleSets_Reimage") + virtualMachineScaleSetsClientReimageResponsePoller, err := virtualMachineScaleSetsClient.BeginReimage(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, &armcompute.VirtualMachineScaleSetsClientBeginReimageOptions{VMScaleSetReimageInput: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientReimageResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSets_Restart + fmt.Println("Call operation: VirtualMachineScaleSets_Restart") + virtualMachineScaleSetsClientRestartResponsePoller, err := virtualMachineScaleSetsClient.BeginRestart(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, &armcompute.VirtualMachineScaleSetsClientBeginRestartOptions{VMInstanceIDs: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientRestartResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSets_ReimageAll + fmt.Println("Call operation: VirtualMachineScaleSets_ReimageAll") + virtualMachineScaleSetsClientReimageAllResponsePoller, err := virtualMachineScaleSetsClient.BeginReimageAll(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, &armcompute.VirtualMachineScaleSetsClientBeginReimageAllOptions{VMInstanceIDs: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientReimageAllResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/virtualMachines/{instanceId} +func (testsuite *VirtualMachineScaleSetTestSuite) TestVirtualMachineScaleSetVMs() { + instanceId := "0" + var err error + // From step VirtualMachineScaleSetVMs_List + fmt.Println("Call operation: VirtualMachineScaleSetVMs_List") + virtualMachineScaleSetVMsClient, err := armcompute.NewVirtualMachineScaleSetVMsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachineScaleSetVMsClientNewListPager := virtualMachineScaleSetVMsClient.NewListPager(testsuite.resourceGroupName, testsuite.vmScaleSetName, &armcompute.VirtualMachineScaleSetVMsClientListOptions{Filter: nil, + Select: nil, + Expand: nil, + }) + for virtualMachineScaleSetVMsClientNewListPager.More() { + _, err := virtualMachineScaleSetVMsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step VirtualMachineScaleSetVMs_Get + fmt.Println("Call operation: VirtualMachineScaleSetVMs_Get") + _, err = virtualMachineScaleSetVMsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, instanceId, &armcompute.VirtualMachineScaleSetVMsClientGetOptions{Expand: nil}) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMs_GetInstanceView + fmt.Println("Call operation: VirtualMachineScaleSetVMs_GetInstanceView") + _, err = virtualMachineScaleSetVMsClient.GetInstanceView(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, instanceId, nil) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMs_Redeploy + fmt.Println("Call operation: VirtualMachineScaleSetVMs_Redeploy") + virtualMachineScaleSetVMsClientRedeployResponsePoller, err := virtualMachineScaleSetVMsClient.BeginRedeploy(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, instanceId, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMsClientRedeployResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMs_Start + fmt.Println("Call operation: VirtualMachineScaleSetVMs_Start") + virtualMachineScaleSetVMsClientStartResponsePoller, err := virtualMachineScaleSetVMsClient.BeginStart(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, instanceId, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMsClientStartResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMs_Restart + fmt.Println("Call operation: VirtualMachineScaleSetVMs_Restart") + virtualMachineScaleSetVMsClientRestartResponsePoller, err := virtualMachineScaleSetVMsClient.BeginRestart(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, instanceId, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMsClientRestartResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMs_Deallocate + fmt.Println("Call operation: VirtualMachineScaleSetVMs_Deallocate") + virtualMachineScaleSetVMsClientDeallocateResponsePoller, err := virtualMachineScaleSetVMsClient.BeginDeallocate(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, instanceId, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMsClientDeallocateResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMs_Reimage + fmt.Println("Call operation: VirtualMachineScaleSetVMs_Reimage") + virtualMachineScaleSetVMsClientReimageResponsePoller, err := virtualMachineScaleSetVMsClient.BeginReimage(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, instanceId, &armcompute.VirtualMachineScaleSetVMsClientBeginReimageOptions{VMScaleSetVMReimageInput: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMsClientReimageResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMs_PowerOff + fmt.Println("Call operation: VirtualMachineScaleSetVMs_PowerOff") + virtualMachineScaleSetVMsClientPowerOffResponsePoller, err := virtualMachineScaleSetVMsClient.BeginPowerOff(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, instanceId, &armcompute.VirtualMachineScaleSetVMsClientBeginPowerOffOptions{SkipShutdown: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMsClientPowerOffResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSetVMs_Delete + fmt.Println("Call operation: VirtualMachineScaleSetVMs_Delete") + virtualMachineScaleSetVMsClientDeleteResponsePoller, err := virtualMachineScaleSetVMsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, instanceId, &armcompute.VirtualMachineScaleSetVMsClientBeginDeleteOptions{ForceDeletion: to.Ptr(true)}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetVMsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} + +func (testsuite *VirtualMachineScaleSetTestSuite) Cleanup() { + var err error + // From step VirtualMachineScaleSets_PowerOff + fmt.Println("Call operation: VirtualMachineScaleSets_PowerOff") + virtualMachineScaleSetsClient, err := armcompute.NewVirtualMachineScaleSetsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + virtualMachineScaleSetsClientPowerOffResponsePoller, err := virtualMachineScaleSetsClient.BeginPowerOff(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, &armcompute.VirtualMachineScaleSetsClientBeginPowerOffOptions{SkipShutdown: nil, + VMInstanceIDs: nil, + }) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientPowerOffResponsePoller) + testsuite.Require().NoError(err) + + // From step VirtualMachineScaleSets_Delete + fmt.Println("Call operation: VirtualMachineScaleSets_Delete") + virtualMachineScaleSetsClientDeleteResponsePoller, err := virtualMachineScaleSetsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.vmScaleSetName, &armcompute.VirtualMachineScaleSetsClientBeginDeleteOptions{ForceDeletion: to.Ptr(true)}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, virtualMachineScaleSetsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesets_client_live_test.go b/sdk/resourcemanager/compute/armcompute/virtualmachinescalesets_client_live_test.go deleted file mode 100644 index e791fbfeef4e..000000000000 --- a/sdk/resourcemanager/compute/armcompute/virtualmachinescalesets_client_live_test.go +++ /dev/null @@ -1,195 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -package armcompute_test - -import ( - "context" - "fmt" - "testing" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" - "github.com/stretchr/testify/suite" -) - -type VirtualMachineScaleSetsClientTestSuite struct { - suite.Suite - - ctx context.Context - cred azcore.TokenCredential - options *arm.ClientOptions - location string - resourceGroupName string - subscriptionID string -} - -func (testsuite *VirtualMachineScaleSetsClientTestSuite) SetupSuite() { - testsuite.ctx = context.Background() - testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.location = testutil.GetEnv("LOCATION", "eastus") - testsuite.subscriptionID = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") - testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/compute/armcompute/testdata") - resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.location) - testsuite.Require().NoError(err) - testsuite.resourceGroupName = *resourceGroup.Name -} - -func (testsuite *VirtualMachineScaleSetsClientTestSuite) TearDownSuite() { - _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionID, testsuite.cred, testsuite.options, testsuite.resourceGroupName) - testsuite.Require().NoError(err) - testutil.StopRecording(testsuite.T()) -} - -func TestVirtualMachineScaleSetsClient(t *testing.T) { - suite.Run(t, new(VirtualMachineScaleSetsClientTestSuite)) -} - -func (testsuite *VirtualMachineScaleSetsClientTestSuite) TestVirtualMachineScaleSetsCRUD() { - // create virtual network and subnet - vnClient, err := armnetwork.NewVirtualNetworksClient(testsuite.subscriptionID, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - vnName := "go-test-network" - subName := "go-test-subnet" - vnPoller, err := vnClient.BeginCreateOrUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - vnName, - armnetwork.VirtualNetwork{ - Location: to.Ptr(testsuite.location), - Properties: &armnetwork.VirtualNetworkPropertiesFormat{ - AddressSpace: &armnetwork.AddressSpace{ - AddressPrefixes: []*string{ - to.Ptr("10.1.0.0/16"), - }, - }, - Subnets: []*armnetwork.Subnet{ - { - Name: to.Ptr(subName), - Properties: &armnetwork.SubnetPropertiesFormat{ - AddressPrefix: to.Ptr("10.1.0.0/24"), - }, - }, - }, - }, - }, - nil, - ) - testsuite.Require().NoError(err) - vnResp, err := testutil.PollForTest(testsuite.ctx, vnPoller) - testsuite.Require().NoError(err) - testsuite.Require().Equal(vnName, *vnResp.Name) - - // create virtual machine scale set - fmt.Println("Call operation: VirtualMachineScaleSets_CreateOrUpdate") - vmssClient, err := armcompute.NewVirtualMachineScaleSetsClient(testsuite.subscriptionID, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - vmssName := "go-test-vmss" - vmssPoller, err := vmssClient.BeginCreateOrUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - vmssName, - armcompute.VirtualMachineScaleSet{ - Location: to.Ptr(testsuite.location), - SKU: &armcompute.SKU{ - //Name: to.Ptr("Basic_A0"), //armcompute.VirtualMachineSizeTypesBasicA0 - Name: to.Ptr("Standard_A0"), //armcompute.VirtualMachineSizeTypesBasicA0 - Capacity: to.Ptr[int64](1), - }, - Properties: &armcompute.VirtualMachineScaleSetProperties{ - Overprovision: to.Ptr(false), - UpgradePolicy: &armcompute.UpgradePolicy{ - Mode: to.Ptr(armcompute.UpgradeModeManual), - AutomaticOSUpgradePolicy: &armcompute.AutomaticOSUpgradePolicy{ - EnableAutomaticOSUpgrade: to.Ptr(false), - DisableAutomaticRollback: to.Ptr(false), - }, - }, - VirtualMachineProfile: &armcompute.VirtualMachineScaleSetVMProfile{ - OSProfile: &armcompute.VirtualMachineScaleSetOSProfile{ - ComputerNamePrefix: to.Ptr("vmss"), - AdminUsername: to.Ptr("sample-user"), - AdminPassword: to.Ptr("Password01!@#"), - }, - StorageProfile: &armcompute.VirtualMachineScaleSetStorageProfile{ - ImageReference: &armcompute.ImageReference{ - Offer: to.Ptr("WindowsServer"), - Publisher: to.Ptr("MicrosoftWindowsServer"), - SKU: to.Ptr("2019-Datacenter"), - Version: to.Ptr("latest"), - }, - }, - NetworkProfile: &armcompute.VirtualMachineScaleSetNetworkProfile{ - NetworkInterfaceConfigurations: []*armcompute.VirtualMachineScaleSetNetworkConfiguration{ - { - Name: to.Ptr(vmssName), - Properties: &armcompute.VirtualMachineScaleSetNetworkConfigurationProperties{ - Primary: to.Ptr(true), - EnableIPForwarding: to.Ptr(true), - IPConfigurations: []*armcompute.VirtualMachineScaleSetIPConfiguration{ - { - Name: to.Ptr(vmssName), - Properties: &armcompute.VirtualMachineScaleSetIPConfigurationProperties{ - Subnet: &armcompute.APIEntityReference{ - ID: to.Ptr(*vnResp.Properties.Subnets[0].ID), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - nil, - ) - testsuite.Require().NoError(err) - vmssResp, err := testutil.PollForTest(testsuite.ctx, vmssPoller) - testsuite.Require().NoError(err) - testsuite.Require().Equal(vmssName, *vmssResp.Name) - - // update - fmt.Println("Call operation: VirtualMachineScaleSets_Update") - updatePollerResp, err := vmssClient.BeginUpdate( - testsuite.ctx, - testsuite.resourceGroupName, - vmssName, - armcompute.VirtualMachineScaleSetUpdate{ - Tags: map[string]*string{ - "test": to.Ptr("live"), - }, - }, - nil, - ) - testsuite.Require().NoError(err) - updateResp, err := testutil.PollForTest(testsuite.ctx, updatePollerResp) - testsuite.Require().NoError(err) - testsuite.Require().Equal("live", *updateResp.Tags["test"]) - - // get - fmt.Println("Call operation: VirtualMachineScaleSets_Get") - getResp, err := vmssClient.Get(testsuite.ctx, testsuite.resourceGroupName, vmssName, nil) - testsuite.Require().NoError(err) - testsuite.Require().Equal(vmssName, *getResp.Name) - - // list - fmt.Println("Call operation: VirtualMachineScaleSets_List") - listResp := vmssClient.NewListPager(testsuite.resourceGroupName, nil) - testsuite.Require().True(listResp.More()) - - // delete - fmt.Println("Call operation: VirtualMachineScaleSets_Delete") - delPoller, err := vmssClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, vmssName, nil) - testsuite.Require().NoError(err) - _, err = testutil.PollForTest(testsuite.ctx, delPoller) - testsuite.Require().NoError(err) -}