|
| 1 | +//go:build go1.18 |
| 2 | +// +build go1.18 |
| 3 | + |
| 4 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 5 | +// Licensed under the MIT License. See License.txt in the project root for license information. |
| 6 | + |
| 7 | +package armloadtesting_test |
| 8 | + |
| 9 | +import ( |
| 10 | + "context" |
| 11 | + "fmt" |
| 12 | + "testing" |
| 13 | + |
| 14 | + "github.com/Azure/azure-sdk-for-go/sdk/azcore" |
| 15 | + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" |
| 16 | + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" |
| 17 | + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" |
| 18 | + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" |
| 19 | + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/loadtesting/armloadtesting" |
| 20 | + "github.com/stretchr/testify/suite" |
| 21 | +) |
| 22 | + |
| 23 | +type LoadtestserviceTestSuite struct { |
| 24 | + suite.Suite |
| 25 | + |
| 26 | + ctx context.Context |
| 27 | + cred azcore.TokenCredential |
| 28 | + options *arm.ClientOptions |
| 29 | + armEndpoint string |
| 30 | + loadTestName string |
| 31 | + location string |
| 32 | + resourceGroupName string |
| 33 | + subscriptionId string |
| 34 | +} |
| 35 | + |
| 36 | +func (testsuite *LoadtestserviceTestSuite) SetupSuite() { |
| 37 | + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/loadtesting/armloadtesting/testdata") |
| 38 | + |
| 39 | + testsuite.ctx = context.Background() |
| 40 | + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) |
| 41 | + testsuite.armEndpoint = "https://management.azure.com" |
| 42 | + testsuite.loadTestName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "loadtest", 14, false) |
| 43 | + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") |
| 44 | + testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") |
| 45 | + testsuite.subscriptionId = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") |
| 46 | + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) |
| 47 | + testsuite.Require().NoError(err) |
| 48 | + testsuite.resourceGroupName = *resourceGroup.Name |
| 49 | +} |
| 50 | + |
| 51 | +func (testsuite *LoadtestserviceTestSuite) TearDownSuite() { |
| 52 | + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) |
| 53 | + testsuite.Require().NoError(err) |
| 54 | + testutil.StopRecording(testsuite.T()) |
| 55 | +} |
| 56 | + |
| 57 | +func TestLoadtestserviceTestSuite(t *testing.T) { |
| 58 | + suite.Run(t, new(LoadtestserviceTestSuite)) |
| 59 | +} |
| 60 | + |
| 61 | +// Microsoft.LoadTestService/loadTests/{loadTestName} |
| 62 | +func (testsuite *LoadtestserviceTestSuite) TestLoadTests() { |
| 63 | + var err error |
| 64 | + // From step LoadTests_CreateOrUpdate |
| 65 | + fmt.Println("Call operation: LoadTests_CreateOrUpdate") |
| 66 | + loadTestsClient, err := armloadtesting.NewLoadTestsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) |
| 67 | + testsuite.Require().NoError(err) |
| 68 | + loadTestsClientCreateOrUpdateResponsePoller, err := loadTestsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.loadTestName, armloadtesting.LoadTestResource{ |
| 69 | + Location: to.Ptr(testsuite.location), |
| 70 | + Tags: map[string]*string{ |
| 71 | + "Team": to.Ptr("Dev Exp"), |
| 72 | + }, |
| 73 | + Properties: &armloadtesting.LoadTestProperties{ |
| 74 | + Description: to.Ptr("This is new load test resource"), |
| 75 | + }, |
| 76 | + }, nil) |
| 77 | + testsuite.Require().NoError(err) |
| 78 | + _, err = testutil.PollForTest(testsuite.ctx, loadTestsClientCreateOrUpdateResponsePoller) |
| 79 | + testsuite.Require().NoError(err) |
| 80 | + |
| 81 | + // From step LoadTests_ListBySubscription |
| 82 | + fmt.Println("Call operation: LoadTests_ListBySubscription") |
| 83 | + loadTestsClientNewListBySubscriptionPager := loadTestsClient.NewListBySubscriptionPager(nil) |
| 84 | + for loadTestsClientNewListBySubscriptionPager.More() { |
| 85 | + _, err := loadTestsClientNewListBySubscriptionPager.NextPage(testsuite.ctx) |
| 86 | + testsuite.Require().NoError(err) |
| 87 | + break |
| 88 | + } |
| 89 | + |
| 90 | + // From step LoadTests_Get |
| 91 | + fmt.Println("Call operation: LoadTests_Get") |
| 92 | + _, err = loadTestsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.loadTestName, nil) |
| 93 | + testsuite.Require().NoError(err) |
| 94 | + |
| 95 | + // From step LoadTests_ListOutboundNetworkDependenciesEndpoints |
| 96 | + fmt.Println("Call operation: LoadTests_ListOutboundNetworkDependenciesEndpoints") |
| 97 | + loadTestsClientNewListOutboundNetworkDependenciesEndpointsPager := loadTestsClient.NewListOutboundNetworkDependenciesEndpointsPager(testsuite.resourceGroupName, testsuite.loadTestName, nil) |
| 98 | + for loadTestsClientNewListOutboundNetworkDependenciesEndpointsPager.More() { |
| 99 | + _, err := loadTestsClientNewListOutboundNetworkDependenciesEndpointsPager.NextPage(testsuite.ctx) |
| 100 | + testsuite.Require().NoError(err) |
| 101 | + break |
| 102 | + } |
| 103 | + |
| 104 | + // From step LoadTests_ListByResourceGroup |
| 105 | + fmt.Println("Call operation: LoadTests_ListByResourceGroup") |
| 106 | + loadTestsClientNewListByResourceGroupPager := loadTestsClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) |
| 107 | + for loadTestsClientNewListByResourceGroupPager.More() { |
| 108 | + _, err := loadTestsClientNewListByResourceGroupPager.NextPage(testsuite.ctx) |
| 109 | + testsuite.Require().NoError(err) |
| 110 | + break |
| 111 | + } |
| 112 | + |
| 113 | + // From step LoadTests_Update |
| 114 | + fmt.Println("Call operation: LoadTests_Update") |
| 115 | + loadTestsClientUpdateResponsePoller, err := loadTestsClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.loadTestName, armloadtesting.LoadTestResourcePatchRequestBody{ |
| 116 | + Tags: map[string]*string{ |
| 117 | + "Division": to.Ptr("LT"), |
| 118 | + "Team": to.Ptr("Dev Exp"), |
| 119 | + }, |
| 120 | + }, nil) |
| 121 | + testsuite.Require().NoError(err) |
| 122 | + _, err = testutil.PollForTest(testsuite.ctx, loadTestsClientUpdateResponsePoller) |
| 123 | + testsuite.Require().NoError(err) |
| 124 | + |
| 125 | + // From step LoadTests_Delete |
| 126 | + fmt.Println("Call operation: LoadTests_Delete") |
| 127 | + loadTestsClientDeleteResponsePoller, err := loadTestsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.loadTestName, nil) |
| 128 | + testsuite.Require().NoError(err) |
| 129 | + _, err = testutil.PollForTest(testsuite.ctx, loadTestsClientDeleteResponsePoller) |
| 130 | + testsuite.Require().NoError(err) |
| 131 | +} |
| 132 | + |
| 133 | +// Microsoft.LoadTestService/operations |
| 134 | +func (testsuite *LoadtestserviceTestSuite) TestOperations() { |
| 135 | + var err error |
| 136 | + // From step Operations_List |
| 137 | + fmt.Println("Call operation: Operations_List") |
| 138 | + operationsClient, err := armloadtesting.NewOperationsClient(testsuite.cred, testsuite.options) |
| 139 | + testsuite.Require().NoError(err) |
| 140 | + operationsClientNewListPager := operationsClient.NewListPager(nil) |
| 141 | + for operationsClientNewListPager.More() { |
| 142 | + _, err := operationsClientNewListPager.NextPage(testsuite.ctx) |
| 143 | + testsuite.Require().NoError(err) |
| 144 | + break |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +// Microsoft.LoadTestService/locations/{location}/quotas/{quotaBucketName} |
| 149 | +func (testsuite *LoadtestserviceTestSuite) TestQuotas() { |
| 150 | + var quotaBucketName string |
| 151 | + var err error |
| 152 | + // From step Quotas_List |
| 153 | + fmt.Println("Call operation: Quotas_List") |
| 154 | + quotasClient, err := armloadtesting.NewQuotasClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) |
| 155 | + testsuite.Require().NoError(err) |
| 156 | + quotasClientNewListPager := quotasClient.NewListPager(testsuite.location, nil) |
| 157 | + for quotasClientNewListPager.More() { |
| 158 | + nextResult, err := quotasClientNewListPager.NextPage(testsuite.ctx) |
| 159 | + testsuite.Require().NoError(err) |
| 160 | + |
| 161 | + quotaBucketName = *nextResult.Value[0].Name |
| 162 | + break |
| 163 | + } |
| 164 | + |
| 165 | + // From step Quotas_Get |
| 166 | + fmt.Println("Call operation: Quotas_Get") |
| 167 | + _, err = quotasClient.Get(testsuite.ctx, testsuite.location, quotaBucketName, nil) |
| 168 | + testsuite.Require().NoError(err) |
| 169 | + |
| 170 | + // From step Quotas_CheckAvailability |
| 171 | + fmt.Println("Call operation: Quotas_CheckAvailability") |
| 172 | + _, err = quotasClient.CheckAvailability(testsuite.ctx, testsuite.location, quotaBucketName, armloadtesting.QuotaBucketRequest{ |
| 173 | + Properties: &armloadtesting.QuotaBucketRequestProperties{ |
| 174 | + CurrentQuota: to.Ptr[int32](40), |
| 175 | + CurrentUsage: to.Ptr[int32](20), |
| 176 | + Dimensions: &armloadtesting.QuotaBucketRequestPropertiesDimensions{ |
| 177 | + Location: to.Ptr(testsuite.location), |
| 178 | + SubscriptionID: to.Ptr(testsuite.subscriptionId), |
| 179 | + }, |
| 180 | + NewQuota: to.Ptr[int32](50), |
| 181 | + }, |
| 182 | + }, nil) |
| 183 | + testsuite.Require().NoError(err) |
| 184 | +} |
0 commit comments