|
| 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 armquota_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/internal/recording" |
| 17 | + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v2/testutil" |
| 18 | + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/quota/armquota" |
| 19 | + "github.com/stretchr/testify/suite" |
| 20 | +) |
| 21 | + |
| 22 | +type QuotaTestSuite struct { |
| 23 | + suite.Suite |
| 24 | + |
| 25 | + ctx context.Context |
| 26 | + cred azcore.TokenCredential |
| 27 | + options *arm.ClientOptions |
| 28 | + armEndpoint string |
| 29 | + location string |
| 30 | + resourceGroupName string |
| 31 | + subscriptionId string |
| 32 | +} |
| 33 | + |
| 34 | +func (testsuite *QuotaTestSuite) SetupSuite() { |
| 35 | + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/quota/armquota/testdata") |
| 36 | + |
| 37 | + testsuite.ctx = context.Background() |
| 38 | + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) |
| 39 | + testsuite.armEndpoint = "https://management.azure.com" |
| 40 | + testsuite.location = recording.GetEnvVariable("LOCATION", "eastus") |
| 41 | + testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") |
| 42 | + testsuite.subscriptionId = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") |
| 43 | + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) |
| 44 | + testsuite.Require().NoError(err) |
| 45 | + testsuite.resourceGroupName = *resourceGroup.Name |
| 46 | +} |
| 47 | + |
| 48 | +func (testsuite *QuotaTestSuite) TearDownSuite() { |
| 49 | + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) |
| 50 | + testsuite.Require().NoError(err) |
| 51 | + testutil.StopRecording(testsuite.T()) |
| 52 | +} |
| 53 | + |
| 54 | +func TestQuotaTestSuite(t *testing.T) { |
| 55 | + suite.Run(t, new(QuotaTestSuite)) |
| 56 | +} |
| 57 | + |
| 58 | +// Microsoft.Quota/quotas/{resourceName} |
| 59 | +func (testsuite *QuotaTestSuite) TestQuota() { |
| 60 | + var id string |
| 61 | + var err error |
| 62 | + |
| 63 | + // From step Quota_List |
| 64 | + fmt.Println("Call operation: Quota_List") |
| 65 | + client, err := armquota.NewClient(testsuite.cred, testsuite.options) |
| 66 | + testsuite.Require().NoError(err) |
| 67 | + clientNewListPager := client.NewListPager("subscriptions/"+testsuite.subscriptionId+"/providers/Microsoft.Network/locations/eastus", nil) |
| 68 | + for clientNewListPager.More() { |
| 69 | + _, err := clientNewListPager.NextPage(testsuite.ctx) |
| 70 | + testsuite.Require().NoError(err) |
| 71 | + break |
| 72 | + } |
| 73 | + |
| 74 | + // From step Quota_Get |
| 75 | + fmt.Println("Call operation: Quota_Get") |
| 76 | + _, err = client.Get(testsuite.ctx, "MinPublicIpInterNetworkPrefixLength", "subscriptions/"+testsuite.subscriptionId+"/providers/Microsoft.Network/locations/eastus", nil) |
| 77 | + testsuite.Require().NoError(err) |
| 78 | + |
| 79 | + // From step QuotaRequestStatus_List |
| 80 | + fmt.Println("Call operation: QuotaRequestStatus_List") |
| 81 | + requestStatusClient, err := armquota.NewRequestStatusClient(testsuite.cred, testsuite.options) |
| 82 | + testsuite.Require().NoError(err) |
| 83 | + requestStatusClientNewListPager := requestStatusClient.NewListPager("subscriptions/"+testsuite.subscriptionId+"/providers/Microsoft.Network/locations/eastus", &armquota.RequestStatusClientListOptions{Filter: nil, |
| 84 | + Top: nil, |
| 85 | + Skiptoken: nil, |
| 86 | + }) |
| 87 | + for requestStatusClientNewListPager.More() { |
| 88 | + nextResult, err := requestStatusClientNewListPager.NextPage(testsuite.ctx) |
| 89 | + testsuite.Require().NoError(err) |
| 90 | + |
| 91 | + id = *nextResult.Value[0].Name |
| 92 | + break |
| 93 | + } |
| 94 | + |
| 95 | + // From step QuotaRequestStatus_Get |
| 96 | + fmt.Println("Call operation: QuotaRequestStatus_Get") |
| 97 | + _, err = requestStatusClient.Get(testsuite.ctx, id, "subscriptions/"+testsuite.subscriptionId+"/providers/Microsoft.Network/locations/eastus", nil) |
| 98 | + testsuite.Require().NoError(err) |
| 99 | +} |
| 100 | + |
| 101 | +// Microsoft.Quota/operations |
| 102 | +func (testsuite *QuotaTestSuite) TestQuotaOperation() { |
| 103 | + var err error |
| 104 | + // From step QuotaOperation_List |
| 105 | + fmt.Println("Call operation: QuotaOperation_List") |
| 106 | + operationClient, err := armquota.NewOperationClient(testsuite.cred, testsuite.options) |
| 107 | + testsuite.Require().NoError(err) |
| 108 | + operationClientNewListPager := operationClient.NewListPager(nil) |
| 109 | + for operationClientNewListPager.More() { |
| 110 | + _, err := operationClientNewListPager.NextPage(testsuite.ctx) |
| 111 | + testsuite.Require().NoError(err) |
| 112 | + break |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +// Microsoft.Quota/usages/{resourceName} |
| 117 | +func (testsuite *QuotaTestSuite) TestUsages() { |
| 118 | + var resourceName string |
| 119 | + var err error |
| 120 | + // From step Usages_List |
| 121 | + fmt.Println("Call operation: Usages_List") |
| 122 | + usagesClient, err := armquota.NewUsagesClient(testsuite.cred, testsuite.options) |
| 123 | + testsuite.Require().NoError(err) |
| 124 | + usagesClientNewListPager := usagesClient.NewListPager("subscriptions/"+testsuite.subscriptionId+"/providers/Microsoft.Network/locations/eastus", nil) |
| 125 | + for usagesClientNewListPager.More() { |
| 126 | + nextResult, err := usagesClientNewListPager.NextPage(testsuite.ctx) |
| 127 | + testsuite.Require().NoError(err) |
| 128 | + |
| 129 | + resourceName = *nextResult.Value[0].Name |
| 130 | + break |
| 131 | + } |
| 132 | + |
| 133 | + // From step Usages_Get |
| 134 | + fmt.Println("Call operation: Usages_Get") |
| 135 | + _, err = usagesClient.Get(testsuite.ctx, resourceName, "subscriptions/"+testsuite.subscriptionId+"/providers/Microsoft.Network/locations/eastus", nil) |
| 136 | + testsuite.Require().NoError(err) |
| 137 | +} |
0 commit comments