From 021f6c929c3b005f86eea77d6d83a667826c2589 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Fri, 12 Jan 2024 16:30:32 +0800 Subject: [PATCH] sdk/resourcemanager/storagecache/armstoragecache live test --- .../amlfilesystem_live_test.go | 217 +++++++++++ .../storagecache/armstoragecache/assets.json | 6 + .../storagecache/armstoragecache/go.mod | 10 +- .../storagecache/armstoragecache/go.sum | 16 + .../armstoragecache/storagecache_live_test.go | 368 ++++++++++++++++++ 5 files changed, 616 insertions(+), 1 deletion(-) create mode 100644 sdk/resourcemanager/storagecache/armstoragecache/amlfilesystem_live_test.go create mode 100644 sdk/resourcemanager/storagecache/armstoragecache/assets.json create mode 100644 sdk/resourcemanager/storagecache/armstoragecache/storagecache_live_test.go diff --git a/sdk/resourcemanager/storagecache/armstoragecache/amlfilesystem_live_test.go b/sdk/resourcemanager/storagecache/armstoragecache/amlfilesystem_live_test.go new file mode 100644 index 000000000000..31aefdd04111 --- /dev/null +++ b/sdk/resourcemanager/storagecache/armstoragecache/amlfilesystem_live_test.go @@ -0,0 +1,217 @@ +//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 armstoragecache_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/internal/recording" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storagecache/armstoragecache/v3" + "github.com/stretchr/testify/suite" +) + +type AmlfilesystemTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + amlFilesystemName string + armEndpoint string + subnetId string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *AmlfilesystemTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/storagecache/armstoragecache/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.amlFilesystemName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "amlfiles", 14, false) + testsuite.armEndpoint = "https://management.azure.com" + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = recording.GetEnvVariable("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 *AmlfilesystemTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestAmlfilesystemTestSuite(t *testing.T) { + suite.Run(t, new(AmlfilesystemTestSuite)) +} + +func (testsuite *AmlfilesystemTestSuite) Prepare() { + var err error + // From step Create_VirtualNetwork + 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('virtualNetworksName'), 'default')]", + }, + }, + "parameters": map[string]any{ + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": "storagecachevnet", + }, + }, + "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", + }, + }, + }, + }, + "tags": map[string]any{}, + }, + }, + } + 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_VirtualNetwork", &deployment) + testsuite.Require().NoError(err) + testsuite.subnetId = deploymentExtend.Properties.Outputs.(map[string]interface{})["subnetId"].(map[string]interface{})["value"].(string) +} + +// Microsoft.StorageCache/amlFilesystems/{amlFilesystemName} +func (testsuite *AmlfilesystemTestSuite) TestAmlFilesystems() { + var err error + // From step amlFilesystems_CreateOrUpdate + fmt.Println("Call operation: amlFilesystems_CreateOrUpdate") + amlFilesystemsClient, err := armstoragecache.NewAmlFilesystemsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + amlFilesystemsClientCreateOrUpdateResponsePoller, err := amlFilesystemsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.amlFilesystemName, armstoragecache.AmlFilesystem{ + Location: to.Ptr(testsuite.location), + Properties: &armstoragecache.AmlFilesystemProperties{ + FilesystemSubnet: to.Ptr(testsuite.subnetId), + MaintenanceWindow: &armstoragecache.AmlFilesystemPropertiesMaintenanceWindow{ + DayOfWeek: to.Ptr(armstoragecache.MaintenanceDayOfWeekTypeMonday), + TimeOfDayUTC: to.Ptr("23:25"), + }, + StorageCapacityTiB: to.Ptr[float32](16), + }, + SKU: &armstoragecache.SKUName{ + Name: to.Ptr("AMLFS-Durable-Premium-125"), + }, + Zones: []*string{ + to.Ptr("1")}, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, amlFilesystemsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step amlFilesystems_List + fmt.Println("Call operation: amlFilesystems_List") + amlFilesystemsClientNewListPager := amlFilesystemsClient.NewListPager(nil) + for amlFilesystemsClientNewListPager.More() { + _, err := amlFilesystemsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step amlFilesystems_Get + fmt.Println("Call operation: amlFilesystems_Get") + _, err = amlFilesystemsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.amlFilesystemName, nil) + testsuite.Require().NoError(err) + + // From step amlFilesystems_ListByResourceGroup + fmt.Println("Call operation: amlFilesystems_ListByResourceGroup") + amlFilesystemsClientNewListByResourceGroupPager := amlFilesystemsClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for amlFilesystemsClientNewListByResourceGroupPager.More() { + _, err := amlFilesystemsClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step amlFilesystems_Update + fmt.Println("Call operation: amlFilesystems_Update") + amlFilesystemsClientUpdateResponsePoller, err := amlFilesystemsClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.amlFilesystemName, armstoragecache.AmlFilesystemUpdate{ + Tags: map[string]*string{ + "Dept": to.Ptr("ContosoAds"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, amlFilesystemsClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step checkAmlFSSubnets + fmt.Println("Call operation: checkAmlFSSubnets") + managementClient, err := armstoragecache.NewManagementClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = managementClient.CheckAmlFSSubnets(testsuite.ctx, &armstoragecache.ManagementClientCheckAmlFSSubnetsOptions{ + AmlFilesystemSubnetInfo: &armstoragecache.AmlFilesystemSubnetInfo{ + Location: to.Ptr(testsuite.location), + FilesystemSubnet: to.Ptr(testsuite.subnetId), + StorageCapacityTiB: to.Ptr[float32](16), + SKU: &armstoragecache.SKUName{ + Name: to.Ptr("AMLFS-Durable-Premium-125"), + }, + }, + }) + testsuite.Require().NoError(err) + + // From step getRequiredAmlFSSubnetsSize + fmt.Println("Call operation: getRequiredAmlFSSubnetsSize") + _, err = managementClient.GetRequiredAmlFSSubnetsSize(testsuite.ctx, &armstoragecache.ManagementClientGetRequiredAmlFSSubnetsSizeOptions{ + RequiredAMLFilesystemSubnetsSizeInfo: &armstoragecache.RequiredAmlFilesystemSubnetsSizeInfo{ + StorageCapacityTiB: to.Ptr[float32](16), + SKU: &armstoragecache.SKUName{ + Name: to.Ptr("AMLFS-Durable-Premium-125"), + }, + }, + }) + testsuite.Require().NoError(err) + + // From step amlFilesystems_Delete + fmt.Println("Call operation: amlFilesystems_Delete") + amlFilesystemsClientDeleteResponsePoller, err := amlFilesystemsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.amlFilesystemName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, amlFilesystemsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/storagecache/armstoragecache/assets.json b/sdk/resourcemanager/storagecache/armstoragecache/assets.json new file mode 100644 index 000000000000..417f6dbab919 --- /dev/null +++ b/sdk/resourcemanager/storagecache/armstoragecache/assets.json @@ -0,0 +1,6 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "go", + "TagPrefix": "go/resourcemanager/storagecache/armstoragecache", + "Tag": "go/resourcemanager/storagecache/armstoragecache_4fa82585b2" +} diff --git a/sdk/resourcemanager/storagecache/armstoragecache/go.mod b/sdk/resourcemanager/storagecache/armstoragecache/go.mod index 78b0a5a1427b..db60b879d751 100644 --- a/sdk/resourcemanager/storagecache/armstoragecache/go.mod +++ b/sdk/resourcemanager/storagecache/armstoragecache/go.mod @@ -5,17 +5,25 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0 + github.com/stretchr/testify v1.8.4 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.2.0 // indirect github.com/golang-jwt/jwt/v5 v5.0.0 // indirect github.com/google/uuid v1.3.1 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/crypto v0.14.0 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/resourcemanager/storagecache/armstoragecache/go.sum b/sdk/resourcemanager/storagecache/armstoragecache/go.sum index 7985f1da436f..88bb72abf2ba 100644 --- a/sdk/resourcemanager/storagecache/armstoragecache/go.sum +++ b/sdk/resourcemanager/storagecache/armstoragecache/go.sum @@ -4,20 +4,31 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZM github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0/go.mod h1:1fXstnBMas5kzG+S3q8UoJcmyU6nUeunJcMDHcRYHhs= github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs= github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI= +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/v2 v2.0.0 h1:PTFGRSlMKCQelWwxUyYVEUqseBJVemLyqWJjvMyt0do= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2 v2.0.0/go.mod h1:LRr2FzBTQlONPPa5HREE5+RjSCTXl7BwOvYOaWTqCaI= +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 v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk= github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= @@ -27,5 +38,10 @@ golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/storagecache/armstoragecache/storagecache_live_test.go b/sdk/resourcemanager/storagecache/armstoragecache/storagecache_live_test.go new file mode 100644 index 000000000000..b3d01c1e715f --- /dev/null +++ b/sdk/resourcemanager/storagecache/armstoragecache/storagecache_live_test.go @@ -0,0 +1,368 @@ +//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 armstoragecache_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/internal/recording" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storagecache/armstoragecache/v3" + "github.com/stretchr/testify/suite" +) + +type StoragecacheTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + armEndpoint string + cacheName string + storageTargetName string + subnetId string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *StoragecacheTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/storagecache/armstoragecache/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.armEndpoint = "https://management.azure.com" + testsuite.cacheName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "cachenam", 14, false) + testsuite.storageTargetName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "storaget", 14, false) + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") + testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = recording.GetEnvVariable("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 *StoragecacheTestSuite) 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 TestStoragecacheTestSuite(t *testing.T) { + suite.Run(t, new(StoragecacheTestSuite)) +} + +func (testsuite *StoragecacheTestSuite) Prepare() { + var err error + // From step Create_VirtualNetwork + 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('virtualNetworksName'), 'default')]", + }, + }, + "parameters": map[string]any{ + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": "storagecachevnet", + }, + }, + "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", + }, + }, + }, + }, + "tags": map[string]any{}, + }, + }, + } + 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_VirtualNetwork", &deployment) + testsuite.Require().NoError(err) + testsuite.subnetId = deploymentExtend.Properties.Outputs.(map[string]interface{})["subnetId"].(map[string]interface{})["value"].(string) + + // From step Caches_CreateOrUpdate + fmt.Println("Call operation: Caches_CreateOrUpdate") + cachesClient, err := armstoragecache.NewCachesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + cachesClientCreateOrUpdateResponsePoller, err := cachesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, armstoragecache.Cache{ + Location: to.Ptr(testsuite.location), + Properties: &armstoragecache.CacheProperties{ + CacheSizeGB: to.Ptr[int32](3072), + Subnet: to.Ptr(testsuite.subnetId), + }, + SKU: &armstoragecache.CacheSKU{ + Name: to.Ptr("Standard_2G"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cachesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.StorageCache/caches/{cacheName} +func (testsuite *StoragecacheTestSuite) TestCaches() { + var err error + // From step Caches_List + fmt.Println("Call operation: Caches_List") + cachesClient, err := armstoragecache.NewCachesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + cachesClientNewListPager := cachesClient.NewListPager(nil) + for cachesClientNewListPager.More() { + _, err := cachesClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Caches_ListByResourceGroup + fmt.Println("Call operation: Caches_ListByResourceGroup") + cachesClientNewListByResourceGroupPager := cachesClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for cachesClientNewListByResourceGroupPager.More() { + _, err := cachesClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Caches_Get + fmt.Println("Call operation: Caches_Get") + _, err = cachesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, nil) + testsuite.Require().NoError(err) + + // From step Caches_Update + fmt.Println("Call operation: Caches_Update") + cachesClientUpdateResponsePoller, err := cachesClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, armstoragecache.Cache{ + Tags: map[string]*string{ + "Dept": to.Ptr("Contoso"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cachesClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step Caches_DebugInfo + fmt.Println("Call operation: Caches_DebugInfo") + cachesClientDebugInfoResponsePoller, err := cachesClient.BeginDebugInfo(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cachesClientDebugInfoResponsePoller) + testsuite.Require().NoError(err) + + // From step Caches_Start + fmt.Println("Call operation: Caches_Start") + cachesClientStartResponsePoller, err := cachesClient.BeginStart(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cachesClientStartResponsePoller) + testsuite.Require().NoError(err) + + // From step Caches_UpgradeFirmware + fmt.Println("Call operation: Caches_UpgradeFirmware") + cachesClientUpgradeFirmwareResponsePoller, err := cachesClient.BeginUpgradeFirmware(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cachesClientUpgradeFirmwareResponsePoller) + testsuite.Require().NoError(err) + + // From step Caches_Flush + fmt.Println("Call operation: Caches_Flush") + cachesClientFlushResponsePoller, err := cachesClient.BeginFlush(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cachesClientFlushResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName} +func (testsuite *StoragecacheTestSuite) TestStorageTargets() { + var err error + // From step StorageTargets_CreateOrUpdate + fmt.Println("Call operation: StorageTargets_CreateOrUpdate") + storageTargetsClient, err := armstoragecache.NewStorageTargetsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + storageTargetsClientCreateOrUpdateResponsePoller, err := storageTargetsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, testsuite.storageTargetName, armstoragecache.StorageTarget{ + Properties: &armstoragecache.StorageTargetProperties{ + Nfs3: &armstoragecache.Nfs3Target{ + Target: to.Ptr("10.0.44.44"), + UsageModel: to.Ptr("READ_ONLY"), + VerificationTimer: to.Ptr[int32](30), + }, + TargetType: to.Ptr(armstoragecache.StorageTargetTypeNfs3), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, storageTargetsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step StorageTargets_ListByCache + fmt.Println("Call operation: StorageTargets_ListByCache") + storageTargetsClientNewListByCachePager := storageTargetsClient.NewListByCachePager(testsuite.resourceGroupName, testsuite.cacheName, nil) + for storageTargetsClientNewListByCachePager.More() { + _, err := storageTargetsClientNewListByCachePager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step StorageTargets_Get + fmt.Println("Call operation: StorageTargets_Get") + _, err = storageTargetsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, testsuite.storageTargetName, nil) + testsuite.Require().NoError(err) + + // From step StorageTargets_DnsRefresh + fmt.Println("Call operation: StorageTargets_DnsRefresh") + storageTargetsClientDNSRefreshResponsePoller, err := storageTargetsClient.BeginDNSRefresh(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, testsuite.storageTargetName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, storageTargetsClientDNSRefreshResponsePoller) + testsuite.Require().NoError(err) + + // From step StorageTarget_Flush + fmt.Println("Call operation: StorageTarget_Flush") + storageTargetClient, err := armstoragecache.NewStorageTargetClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + storageTargetClientFlushResponsePoller, err := storageTargetClient.BeginFlush(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, testsuite.storageTargetName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, storageTargetClientFlushResponsePoller) + testsuite.Require().NoError(err) + + // From step StorageTarget_Invalidate + fmt.Println("Call operation: StorageTarget_Invalidate") + storageTargetClientInvalidateResponsePoller, err := storageTargetClient.BeginInvalidate(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, testsuite.storageTargetName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, storageTargetClientInvalidateResponsePoller) + testsuite.Require().NoError(err) + + // From step StorageTarget_Resume + fmt.Println("Call operation: StorageTarget_Resume") + storageTargetClientResumeResponsePoller, err := storageTargetClient.BeginResume(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, testsuite.storageTargetName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, storageTargetClientResumeResponsePoller) + testsuite.Require().NoError(err) + + // From step StorageTarget_Suspend + fmt.Println("Call operation: StorageTarget_Suspend") + storageTargetClientSuspendResponsePoller, err := storageTargetClient.BeginSuspend(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, testsuite.storageTargetName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, storageTargetClientSuspendResponsePoller) + testsuite.Require().NoError(err) + + // From step StorageTargets_Delete + fmt.Println("Call operation: StorageTargets_Delete") + storageTargetsClientDeleteResponsePoller, err := storageTargetsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, testsuite.storageTargetName, &armstoragecache.StorageTargetsClientBeginDeleteOptions{Force: nil}) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, storageTargetsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.StorageCache/operations +func (testsuite *StoragecacheTestSuite) TestOperations() { + var err error + // From step Operations_List + fmt.Println("Call operation: Operations_List") + operationsClient, err := armstoragecache.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.StorageCache/skus +func (testsuite *StoragecacheTestSuite) TestSkus() { + var err error + // From step Skus_List + fmt.Println("Call operation: Skus_List") + sKUsClient, err := armstoragecache.NewSKUsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + sKUsClientNewListPager := sKUsClient.NewListPager(nil) + for sKUsClientNewListPager.More() { + _, err := sKUsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} + +// Microsoft.StorageCache/usageModels +func (testsuite *StoragecacheTestSuite) TestUsageModels() { + var err error + // From step UsageModels_List + fmt.Println("Call operation: UsageModels_List") + usageModelsClient, err := armstoragecache.NewUsageModelsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + usageModelsClientNewListPager := usageModelsClient.NewListPager(nil) + for usageModelsClientNewListPager.More() { + _, err := usageModelsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} + +// Microsoft.StorageCache/locations/{location}/usages +func (testsuite *StoragecacheTestSuite) TestAscUsages() { + var err error + // From step AscUsages_List + fmt.Println("Call operation: AscUsages_List") + ascUsagesClient, err := armstoragecache.NewAscUsagesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + ascUsagesClientNewListPager := ascUsagesClient.NewListPager(testsuite.location, nil) + for ascUsagesClientNewListPager.More() { + _, err := ascUsagesClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} + +func (testsuite *StoragecacheTestSuite) Cleanup() { + var err error + // From step Caches_Stop + fmt.Println("Call operation: Caches_Stop") + cachesClient, err := armstoragecache.NewCachesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + cachesClientStopResponsePoller, err := cachesClient.BeginStop(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cachesClientStopResponsePoller) + testsuite.Require().NoError(err) + + // From step Caches_Delete + fmt.Println("Call operation: Caches_Delete") + cachesClientDeleteResponsePoller, err := cachesClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.cacheName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cachesClientDeleteResponsePoller) + testsuite.Require().NoError(err) +}