github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/usage_live_test.go (about)

     1  //go:build go1.18
     2  // +build go1.18
     3  
     4  // Copyright (c) Microsoft Corporation. All rights reserved.
     5  // Licensed under the MIT License. See License.txt in the project root for license information.
     6  
     7  package armnetwork_test
     8  
     9  import (
    10  	"context"
    11  	"fmt"
    12  	"testing"
    13  
    14  	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
    15  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
    16  	"github.com/Azure/azure-sdk-for-go/sdk/internal/recording"
    17  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/v3/testutil"
    18  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"
    19  	"github.com/stretchr/testify/suite"
    20  )
    21  
    22  type UsageTestSuite struct {
    23  	suite.Suite
    24  
    25  	ctx               context.Context
    26  	cred              azcore.TokenCredential
    27  	options           *arm.ClientOptions
    28  	location          string
    29  	resourceGroupName string
    30  	subscriptionId    string
    31  }
    32  
    33  func (testsuite *UsageTestSuite) SetupSuite() {
    34  	testutil.StartRecording(testsuite.T(), pathToPackage)
    35  
    36  	testsuite.ctx = context.Background()
    37  	testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T())
    38  	testsuite.location = recording.GetEnvVariable("LOCATION", "westus")
    39  	testsuite.resourceGroupName = recording.GetEnvVariable("RESOURCE_GROUP_NAME", "scenarioTestTempGroup")
    40  	testsuite.subscriptionId = recording.GetEnvVariable("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
    41  	resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location)
    42  	testsuite.Require().NoError(err)
    43  	testsuite.resourceGroupName = *resourceGroup.Name
    44  }
    45  
    46  func (testsuite *UsageTestSuite) TearDownSuite() {
    47  	_, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName)
    48  	testsuite.Require().NoError(err)
    49  	testutil.StopRecording(testsuite.T())
    50  }
    51  
    52  func TestUsageTestSuite(t *testing.T) {
    53  	suite.Run(t, new(UsageTestSuite))
    54  }
    55  
    56  // Microsoft.Network/locations/{location}/usages
    57  func (testsuite *UsageTestSuite) TestUsages() {
    58  	var err error
    59  	// From step Usages_List
    60  	fmt.Println("Call operation: Usages_List")
    61  	usagesClient, err := armnetwork.NewUsagesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options)
    62  	testsuite.Require().NoError(err)
    63  	usagesClientNewListPager := usagesClient.NewListPager(testsuite.location, nil)
    64  	for usagesClientNewListPager.More() {
    65  		_, err := usagesClientNewListPager.NextPage(testsuite.ctx)
    66  		testsuite.Require().NoError(err)
    67  		break
    68  	}
    69  }