From 36f766d2feba70f64bed923c23b57602998e16c8 Mon Sep 17 00:00:00 2001 From: Peng Jiahui <46921893+Alancere@users.noreply.github.com> Date: Thu, 4 May 2023 16:20:54 +0800 Subject: [PATCH] add sdk/resourcemanager/cosmos/armcosmos live test (#20705) * add sdk/resourcemanager/cosmos/armcosmos live test * update assets.json * update assets.json * update assets.json * update assets.json --- .../cosmos/armcosmos/assets.json | 2 +- .../armcosmos/cassandraresources_live_test.go | 266 ++++++++++ .../armcosmos/databaseaccounts_live_test.go | 223 +++++++++ sdk/resourcemanager/cosmos/armcosmos/go.mod | 18 +- sdk/resourcemanager/cosmos/armcosmos/go.sum | 46 +- .../armcosmos/gremlinresources_live_test.go | 293 +++++++++++ .../armcosmos/mongodbresources_live_test.go | 256 ++++++++++ .../cosmos/armcosmos/operations_live_test.go | 88 ++++ .../privateendpointconnection_live_test.go | 293 +++++++++++ .../cosmos/armcosmos/services_live_test.go | 122 +++++ .../armcosmos/sqlresources_live_test.go | 465 ++++++++++++++++++ .../armcosmos/tableresources_live_test.go | 166 +++++++ 12 files changed, 2220 insertions(+), 18 deletions(-) create mode 100644 sdk/resourcemanager/cosmos/armcosmos/cassandraresources_live_test.go create mode 100644 sdk/resourcemanager/cosmos/armcosmos/databaseaccounts_live_test.go create mode 100644 sdk/resourcemanager/cosmos/armcosmos/gremlinresources_live_test.go create mode 100644 sdk/resourcemanager/cosmos/armcosmos/mongodbresources_live_test.go create mode 100644 sdk/resourcemanager/cosmos/armcosmos/operations_live_test.go create mode 100644 sdk/resourcemanager/cosmos/armcosmos/privateendpointconnection_live_test.go create mode 100644 sdk/resourcemanager/cosmos/armcosmos/services_live_test.go create mode 100644 sdk/resourcemanager/cosmos/armcosmos/sqlresources_live_test.go create mode 100644 sdk/resourcemanager/cosmos/armcosmos/tableresources_live_test.go diff --git a/sdk/resourcemanager/cosmos/armcosmos/assets.json b/sdk/resourcemanager/cosmos/armcosmos/assets.json index 583d0157f601..512680b33eee 100644 --- a/sdk/resourcemanager/cosmos/armcosmos/assets.json +++ b/sdk/resourcemanager/cosmos/armcosmos/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/resourcemanager/cosmos/armcosmos", - "Tag": "go/resourcemanager/cosmos/armcosmos_f300ab67c7" + "Tag": "go/resourcemanager/cosmos/armcosmos_b256b80d8d" } diff --git a/sdk/resourcemanager/cosmos/armcosmos/cassandraresources_live_test.go b/sdk/resourcemanager/cosmos/armcosmos/cassandraresources_live_test.go new file mode 100644 index 000000000000..5d02a42eadb4 --- /dev/null +++ b/sdk/resourcemanager/cosmos/armcosmos/cassandraresources_live_test.go @@ -0,0 +1,266 @@ +//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 armcosmos_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/cosmos/armcosmos/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type CassandraResourcesTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + accountName string + keyspaceName string + tableName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *CassandraResourcesTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmos/armcosmos/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.accountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "accountn", 14, true) + testsuite.keyspaceName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "keyspace", 14, false) + testsuite.tableName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "tablenam", 14, false) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + 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 *CassandraResourcesTestSuite) 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 TestCassandraResourcesTestSuite(t *testing.T) { + suite.Run(t, new(CassandraResourcesTestSuite)) +} + +func (testsuite *CassandraResourcesTestSuite) Prepare() { + var err error + // From step DatabaseAccounts_CreateOrUpdate + fmt.Println("Call operation: DatabaseAccounts_CreateOrUpdate") + databaseAccountsClient, err := armcosmos.NewDatabaseAccountsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + databaseAccountsClientCreateOrUpdateResponsePoller, err := databaseAccountsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.DatabaseAccountCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Properties: &armcosmos.DatabaseAccountCreateUpdateProperties{ + Capabilities: []*armcosmos.Capability{ + { + Name: to.Ptr("EnableCassandra"), + }}, + CreateMode: to.Ptr(armcosmos.CreateModeDefault), + DatabaseAccountOfferType: to.Ptr("Standard"), + Locations: []*armcosmos.Location{ + { + FailoverPriority: to.Ptr[int32](0), + IsZoneRedundant: to.Ptr(false), + LocationName: to.Ptr(testsuite.location), + }}, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/cassandraKeyspaces/{keyspaceName} +func (testsuite *CassandraResourcesTestSuite) TestCassandraKeyspace() { + var err error + // From step CassandraResources_CreateUpdateCassandraKeyspace + fmt.Println("Call operation: CassandraResources_CreateUpdateCassandraKeyspace") + cassandraResourcesClient, err := armcosmos.NewCassandraResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + cassandraResourcesClientCreateUpdateCassandraKeyspaceResponsePoller, err := cassandraResourcesClient.BeginCreateUpdateCassandraKeyspace(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, armcosmos.CassandraKeyspaceCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.CassandraKeyspaceCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{ + Throughput: to.Ptr[int32](2000), + }, + Resource: &armcosmos.CassandraKeyspaceResource{ + ID: to.Ptr(testsuite.keyspaceName), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cassandraResourcesClientCreateUpdateCassandraKeyspaceResponsePoller) + testsuite.Require().NoError(err) + + // From step CassandraResources_ListCassandraKeyspaces + fmt.Println("Call operation: CassandraResources_ListCassandraKeyspaces") + cassandraResourcesClientNewListCassandraKeyspacesPager := cassandraResourcesClient.NewListCassandraKeyspacesPager(testsuite.resourceGroupName, testsuite.accountName, nil) + for cassandraResourcesClientNewListCassandraKeyspacesPager.More() { + _, err := cassandraResourcesClientNewListCassandraKeyspacesPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step CassandraResources_GetCassandraKeyspaceThroughput + fmt.Println("Call operation: CassandraResources_GetCassandraKeyspaceThroughput") + _, err = cassandraResourcesClient.GetCassandraKeyspaceThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, nil) + testsuite.Require().NoError(err) + + // From step CassandraResources_GetCassandraKeyspace + fmt.Println("Call operation: CassandraResources_GetCassandraKeyspace") + _, err = cassandraResourcesClient.GetCassandraKeyspace(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, nil) + testsuite.Require().NoError(err) + + // From step CassandraResources_MigrateCassandraKeyspaceToAutoscale + fmt.Println("Call operation: CassandraResources_MigrateCassandraKeyspaceToAutoscale") + cassandraResourcesClientMigrateCassandraKeyspaceToAutoscaleResponsePoller, err := cassandraResourcesClient.BeginMigrateCassandraKeyspaceToAutoscale(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cassandraResourcesClientMigrateCassandraKeyspaceToAutoscaleResponsePoller) + testsuite.Require().NoError(err) + + // From step CassandraResources_MigrateCassandraKeyspaceToManualThroughput + fmt.Println("Call operation: CassandraResources_MigrateCassandraKeyspaceToManualThroughput") + cassandraResourcesClientMigrateCassandraKeyspaceToManualThroughputResponsePoller, err := cassandraResourcesClient.BeginMigrateCassandraKeyspaceToManualThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cassandraResourcesClientMigrateCassandraKeyspaceToManualThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step CassandraResources_UpdateCassandraKeyspaceThroughput + fmt.Println("Call operation: CassandraResources_UpdateCassandraKeyspaceThroughput") + cassandraResourcesClientUpdateCassandraKeyspaceThroughputResponsePoller, err := cassandraResourcesClient.BeginUpdateCassandraKeyspaceThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, armcosmos.ThroughputSettingsUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.ThroughputSettingsUpdateProperties{ + Resource: &armcosmos.ThroughputSettingsResource{ + Throughput: to.Ptr[int32](400), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cassandraResourcesClientUpdateCassandraKeyspaceThroughputResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/cassandraKeyspaces/{keyspaceName}/tables/{tableName} +func (testsuite *CassandraResourcesTestSuite) TestCassandraTable() { + var err error + // From step CassandraResources_CreateUpdateCassandraTable + fmt.Println("Call operation: CassandraResources_CreateUpdateCassandraTable") + cassandraResourcesClient, err := armcosmos.NewCassandraResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + cassandraResourcesClientCreateUpdateCassandraTableResponsePoller, err := cassandraResourcesClient.BeginCreateUpdateCassandraTable(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, testsuite.tableName, armcosmos.CassandraTableCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.CassandraTableCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{ + Throughput: to.Ptr[int32](2000), + }, + Resource: &armcosmos.CassandraTableResource{ + Schema: &armcosmos.CassandraSchema{ + Columns: []*armcosmos.Column{ + { + Name: to.Ptr("columnA"), + Type: to.Ptr("Ascii"), + }}, + PartitionKeys: []*armcosmos.CassandraPartitionKey{ + { + Name: to.Ptr("columnA"), + }}, + }, + DefaultTTL: to.Ptr[int32](100), + ID: to.Ptr(testsuite.tableName), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cassandraResourcesClientCreateUpdateCassandraTableResponsePoller) + testsuite.Require().NoError(err) + + // From step CassandraResources_GetCassandraTable + fmt.Println("Call operation: CassandraResources_GetCassandraTable") + _, err = cassandraResourcesClient.GetCassandraTable(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, testsuite.tableName, nil) + testsuite.Require().NoError(err) + + // From step CassandraResources_ListCassandraTables + fmt.Println("Call operation: CassandraResources_ListCassandraTables") + cassandraResourcesClientNewListCassandraTablesPager := cassandraResourcesClient.NewListCassandraTablesPager(testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, nil) + for cassandraResourcesClientNewListCassandraTablesPager.More() { + _, err := cassandraResourcesClientNewListCassandraTablesPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step CassandraResources_GetCassandraTableThroughput + fmt.Println("Call operation: CassandraResources_GetCassandraTableThroughput") + _, err = cassandraResourcesClient.GetCassandraTableThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, testsuite.tableName, nil) + testsuite.Require().NoError(err) + + // From step CassandraResources_MigrateCassandraTableToAutoscale + fmt.Println("Call operation: CassandraResources_MigrateCassandraTableToAutoscale") + cassandraResourcesClientMigrateCassandraTableToAutoscaleResponsePoller, err := cassandraResourcesClient.BeginMigrateCassandraTableToAutoscale(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, testsuite.tableName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cassandraResourcesClientMigrateCassandraTableToAutoscaleResponsePoller) + testsuite.Require().NoError(err) + + // From step CassandraResources_MigrateCassandraTableToManualThroughput + fmt.Println("Call operation: CassandraResources_MigrateCassandraTableToManualThroughput") + cassandraResourcesClientMigrateCassandraTableToManualThroughputResponsePoller, err := cassandraResourcesClient.BeginMigrateCassandraTableToManualThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, testsuite.tableName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cassandraResourcesClientMigrateCassandraTableToManualThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step CassandraResources_UpdateCassandraTableThroughput + fmt.Println("Call operation: CassandraResources_UpdateCassandraTableThroughput") + cassandraResourcesClientUpdateCassandraTableThroughputResponsePoller, err := cassandraResourcesClient.BeginUpdateCassandraTableThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, testsuite.tableName, armcosmos.ThroughputSettingsUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.ThroughputSettingsUpdateProperties{ + Resource: &armcosmos.ThroughputSettingsResource{ + Throughput: to.Ptr[int32](400), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cassandraResourcesClientUpdateCassandraTableThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step CassandraResources_DeleteCassandraTable + fmt.Println("Call operation: CassandraResources_DeleteCassandraTable") + cassandraResourcesClientDeleteCassandraTableResponsePoller, err := cassandraResourcesClient.BeginDeleteCassandraTable(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, testsuite.tableName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cassandraResourcesClientDeleteCassandraTableResponsePoller) + testsuite.Require().NoError(err) +} + +func (testsuite *CassandraResourcesTestSuite) Cleanup() { + var err error + // From step CassandraResources_DeleteCassandraKeyspace + fmt.Println("Call operation: CassandraResources_DeleteCassandraKeyspace") + cassandraResourcesClient, err := armcosmos.NewCassandraResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + cassandraResourcesClientDeleteCassandraKeyspaceResponsePoller, err := cassandraResourcesClient.BeginDeleteCassandraKeyspace(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.keyspaceName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, cassandraResourcesClientDeleteCassandraKeyspaceResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/cosmos/armcosmos/databaseaccounts_live_test.go b/sdk/resourcemanager/cosmos/armcosmos/databaseaccounts_live_test.go new file mode 100644 index 000000000000..3a8064d476e4 --- /dev/null +++ b/sdk/resourcemanager/cosmos/armcosmos/databaseaccounts_live_test.go @@ -0,0 +1,223 @@ +//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 armcosmos_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/cosmos/armcosmos/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type DatabaseAccountsTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + accountName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *DatabaseAccountsTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmos/armcosmos/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.accountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "accountn", 14, true) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + 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 *DatabaseAccountsTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestDatabaseAccountsTestSuite(t *testing.T) { + suite.Run(t, new(DatabaseAccountsTestSuite)) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName} +func (testsuite *DatabaseAccountsTestSuite) TestDatabaseAccounts() { + var err error + // From step DatabaseAccounts_CheckNameExists + fmt.Println("Call operation: DatabaseAccounts_CheckNameExists") + databaseAccountsClient, err := armcosmos.NewDatabaseAccountsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = databaseAccountsClient.CheckNameExists(testsuite.ctx, testsuite.accountName, nil) + testsuite.Require().NoError(err) + + // From step DatabaseAccounts_CreateOrUpdate + fmt.Println("Call operation: DatabaseAccounts_CreateOrUpdate") + databaseAccountsClientCreateOrUpdateResponsePoller, err := databaseAccountsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.DatabaseAccountCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Properties: &armcosmos.DatabaseAccountCreateUpdateProperties{ + CreateMode: to.Ptr(armcosmos.CreateModeDefault), + DatabaseAccountOfferType: to.Ptr("Standard"), + Locations: []*armcosmos.Location{ + { + FailoverPriority: to.Ptr[int32](2), + LocationName: to.Ptr("southcentralus"), + }, + { + FailoverPriority: to.Ptr[int32](1), + LocationName: to.Ptr("eastus"), + }, + { + FailoverPriority: to.Ptr[int32](0), + LocationName: to.Ptr("westus"), + }}, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step DatabaseAccounts_List + fmt.Println("Call operation: DatabaseAccounts_List") + databaseAccountsClientNewListPager := databaseAccountsClient.NewListPager(nil) + for databaseAccountsClientNewListPager.More() { + _, err := databaseAccountsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DatabaseAccounts_ListUsages + fmt.Println("Call operation: DatabaseAccounts_ListUsages") + databaseAccountsClientNewListUsagesPager := databaseAccountsClient.NewListUsagesPager(testsuite.resourceGroupName, testsuite.accountName, &armcosmos.DatabaseAccountsClientListUsagesOptions{Filter: to.Ptr("")}) + for databaseAccountsClientNewListUsagesPager.More() { + _, err := databaseAccountsClientNewListUsagesPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DatabaseAccounts_GetReadOnlyKeys + fmt.Println("Call operation: DatabaseAccounts_GetReadOnlyKeys") + _, err = databaseAccountsClient.GetReadOnlyKeys(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, nil) + testsuite.Require().NoError(err) + + // From step DatabaseAccounts_ListByResourceGroup + fmt.Println("Call operation: DatabaseAccounts_ListByResourceGroup") + databaseAccountsClientNewListByResourceGroupPager := databaseAccountsClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for databaseAccountsClientNewListByResourceGroupPager.More() { + _, err := databaseAccountsClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DatabaseAccounts_ListMetricDefinitions + fmt.Println("Call operation: DatabaseAccounts_ListMetricDefinitions") + databaseAccountsClientNewListMetricDefinitionsPager := databaseAccountsClient.NewListMetricDefinitionsPager(testsuite.resourceGroupName, testsuite.accountName, nil) + for databaseAccountsClientNewListMetricDefinitionsPager.More() { + _, err := databaseAccountsClientNewListMetricDefinitionsPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DatabaseAccounts_Get + fmt.Println("Call operation: DatabaseAccounts_Get") + _, err = databaseAccountsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, nil) + testsuite.Require().NoError(err) + + // From step DatabaseAccounts_Update + fmt.Println("Call operation: DatabaseAccounts_Update") + databaseAccountsClientUpdateResponsePoller, err := databaseAccountsClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.DatabaseAccountUpdateParameters{ + Tags: map[string]*string{ + "dept": to.Ptr("finance"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step DatabaseAccounts_RegenerateKey + fmt.Println("Call operation: DatabaseAccounts_RegenerateKey") + databaseAccountsClientRegenerateKeyResponsePoller, err := databaseAccountsClient.BeginRegenerateKey(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.DatabaseAccountRegenerateKeyParameters{ + KeyKind: to.Ptr(armcosmos.KeyKindPrimary), + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientRegenerateKeyResponsePoller) + testsuite.Require().NoError(err) + + // From step DatabaseAccounts_ListReadOnlyKeys + fmt.Println("Call operation: DatabaseAccounts_ListReadOnlyKeys") + _, err = databaseAccountsClient.ListReadOnlyKeys(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, nil) + testsuite.Require().NoError(err) + + // From step DatabaseAccounts_ListConnectionStrings + fmt.Println("Call operation: DatabaseAccounts_ListConnectionStrings") + _, err = databaseAccountsClient.ListConnectionStrings(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, nil) + testsuite.Require().NoError(err) + + // From step DatabaseAccounts_ListKeys + fmt.Println("Call operation: DatabaseAccounts_ListKeys") + _, err = databaseAccountsClient.ListKeys(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, nil) + testsuite.Require().NoError(err) + + // From step DatabaseAccounts_FailoverPriorityChange + fmt.Println("Call operation: DatabaseAccounts_FailoverPriorityChange") + databaseAccountsClientFailoverPriorityChangeResponsePoller, err := databaseAccountsClient.BeginFailoverPriorityChange(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.FailoverPolicies{ + FailoverPolicies: []*armcosmos.FailoverPolicy{ + { + FailoverPriority: to.Ptr[int32](0), + LocationName: to.Ptr("eastus"), + }, + { + FailoverPriority: to.Ptr[int32](2), + LocationName: to.Ptr("southcentralus"), + }, + { + FailoverPriority: to.Ptr[int32](1), + LocationName: to.Ptr("westus"), + }}, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientFailoverPriorityChangeResponsePoller) + testsuite.Require().NoError(err) + + // From step RestorableDatabaseAccounts_ListByLocation + fmt.Println("Call operation: RestorableDatabaseAccounts_ListByLocation") + restorableDatabaseAccountsClient, err := armcosmos.NewRestorableDatabaseAccountsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + restorableDatabaseAccountsClientNewListByLocationPager := restorableDatabaseAccountsClient.NewListByLocationPager(testsuite.location, nil) + for restorableDatabaseAccountsClientNewListByLocationPager.More() { + _, err := restorableDatabaseAccountsClientNewListByLocationPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step RestorableDatabaseAccounts_List + fmt.Println("Call operation: RestorableDatabaseAccounts_List") + restorableDatabaseAccountsClientNewListPager := restorableDatabaseAccountsClient.NewListPager(nil) + for restorableDatabaseAccountsClientNewListPager.More() { + _, err := restorableDatabaseAccountsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step DatabaseAccounts_Delete + fmt.Println("Call operation: DatabaseAccounts_Delete") + databaseAccountsClientDeleteResponsePoller, err := databaseAccountsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/cosmos/armcosmos/go.mod b/sdk/resourcemanager/cosmos/armcosmos/go.mod index 7e1ccc0fbbd8..635ba01cfcae 100644 --- a/sdk/resourcemanager/cosmos/armcosmos/go.mod +++ b/sdk/resourcemanager/cosmos/armcosmos/go.mod @@ -3,19 +3,27 @@ module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos/v2 go 1.18 require ( - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.5.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 + github.com/stretchr/testify v1.8.2 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.1.0 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/google/uuid v1.3.0 // 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.6.0 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/net v0.8.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/resourcemanager/cosmos/armcosmos/go.sum b/sdk/resourcemanager/cosmos/armcosmos/go.sum index 8ba445a8c4da..e625fa8fa1b9 100644 --- a/sdk/resourcemanager/cosmos/armcosmos/go.sum +++ b/sdk/resourcemanager/cosmos/armcosmos/go.sum @@ -1,31 +1,53 @@ -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJVR2cMC8lvZcimipiEY= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.5.0 h1:xGLAFFd9D3iLGxYiUGPdITSzsFmU1K8VtfuUHWAoN7M= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.5.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 h1:uqM+VoHjVH6zdlkLF2b6O0ZANcHoj3rO0PoQ3jglUJA= github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2/go.mod h1:twTKAa1E6hLmSDjLhaCkbTMQKc7p/rNLU40rLxGEOCI= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= +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/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.9.0 h1:UE9n9rkJF62ArLb1F3DEjRt8O3jLwMWdSoypKV4f3MU= github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= +github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/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/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +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.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +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/cosmos/armcosmos/gremlinresources_live_test.go b/sdk/resourcemanager/cosmos/armcosmos/gremlinresources_live_test.go new file mode 100644 index 000000000000..aa932ebd6385 --- /dev/null +++ b/sdk/resourcemanager/cosmos/armcosmos/gremlinresources_live_test.go @@ -0,0 +1,293 @@ +//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 armcosmos_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/cosmos/armcosmos/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type GremlinResourcesTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + accountName string + databaseName string + graphName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *GremlinResourcesTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmos/armcosmos/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.accountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "accountn", 14, true) + testsuite.databaseName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "gremlindb", 15, false) + testsuite.graphName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "graphnam", 14, false) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + 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 *GremlinResourcesTestSuite) 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 TestGremlinResourcesTestSuite(t *testing.T) { + suite.Run(t, new(GremlinResourcesTestSuite)) +} + +func (testsuite *GremlinResourcesTestSuite) Prepare() { + var err error + // From step DatabaseAccounts_CreateOrUpdate + fmt.Println("Call operation: DatabaseAccounts_CreateOrUpdate") + databaseAccountsClient, err := armcosmos.NewDatabaseAccountsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + databaseAccountsClientCreateOrUpdateResponsePoller, err := databaseAccountsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.DatabaseAccountCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Properties: &armcosmos.DatabaseAccountCreateUpdateProperties{ + Capabilities: []*armcosmos.Capability{ + { + Name: to.Ptr("EnableGremlin"), + }}, + CreateMode: to.Ptr(armcosmos.CreateModeDefault), + DatabaseAccountOfferType: to.Ptr("Standard"), + Locations: []*armcosmos.Location{ + { + FailoverPriority: to.Ptr[int32](0), + IsZoneRedundant: to.Ptr(false), + LocationName: to.Ptr(testsuite.location), + }}, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step GremlinResources_CreateUpdateGremlinDatabase + fmt.Println("Call operation: GremlinResources_CreateUpdateGremlinDatabase") + gremlinResourcesClient, err := armcosmos.NewGremlinResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + gremlinResourcesClientCreateUpdateGremlinDatabaseResponsePoller, err := gremlinResourcesClient.BeginCreateUpdateGremlinDatabase(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, armcosmos.GremlinDatabaseCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.GremlinDatabaseCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{ + Throughput: to.Ptr[int32](2000), + }, + Resource: &armcosmos.GremlinDatabaseResource{ + ID: to.Ptr(testsuite.databaseName), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, gremlinResourcesClientCreateUpdateGremlinDatabaseResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/gremlinDatabases/{databaseName} +func (testsuite *GremlinResourcesTestSuite) TestGremlinDatabase() { + var err error + // From step GremlinResources_ListGremlinDatabases + fmt.Println("Call operation: GremlinResources_ListGremlinDatabases") + gremlinResourcesClient, err := armcosmos.NewGremlinResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + gremlinResourcesClientNewListGremlinDatabasesPager := gremlinResourcesClient.NewListGremlinDatabasesPager(testsuite.resourceGroupName, testsuite.accountName, nil) + for gremlinResourcesClientNewListGremlinDatabasesPager.More() { + _, err := gremlinResourcesClientNewListGremlinDatabasesPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step GremlinResources_GetGremlinDatabaseThroughput + fmt.Println("Call operation: GremlinResources_GetGremlinDatabaseThroughput") + _, err = gremlinResourcesClient.GetGremlinDatabaseThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + + // From step GremlinResources_GetGremlinDatabase + fmt.Println("Call operation: GremlinResources_GetGremlinDatabase") + _, err = gremlinResourcesClient.GetGremlinDatabase(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + + // From step GremlinResources_MigrateGremlinDatabaseToAutoscale + fmt.Println("Call operation: GremlinResources_MigrateGremlinDatabaseToAutoscale") + gremlinResourcesClientMigrateGremlinDatabaseToAutoscaleResponsePoller, err := gremlinResourcesClient.BeginMigrateGremlinDatabaseToAutoscale(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, gremlinResourcesClientMigrateGremlinDatabaseToAutoscaleResponsePoller) + testsuite.Require().NoError(err) + + // From step GremlinResources_MigrateGremlinDatabaseToManualThroughput + fmt.Println("Call operation: GremlinResources_MigrateGremlinDatabaseToManualThroughput") + gremlinResourcesClientMigrateGremlinDatabaseToManualThroughputResponsePoller, err := gremlinResourcesClient.BeginMigrateGremlinDatabaseToManualThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, gremlinResourcesClientMigrateGremlinDatabaseToManualThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step GremlinResources_UpdateGremlinDatabaseThroughput + fmt.Println("Call operation: GremlinResources_UpdateGremlinDatabaseThroughput") + gremlinResourcesClientUpdateGremlinDatabaseThroughputResponsePoller, err := gremlinResourcesClient.BeginUpdateGremlinDatabaseThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, armcosmos.ThroughputSettingsUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.ThroughputSettingsUpdateProperties{ + Resource: &armcosmos.ThroughputSettingsResource{ + Throughput: to.Ptr[int32](400), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, gremlinResourcesClientUpdateGremlinDatabaseThroughputResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/gremlinDatabases/{databaseName}/graphs/{graphName} +func (testsuite *GremlinResourcesTestSuite) TestGremlinGraph() { + var err error + // From step GremlinResources_CreateUpdateGremlinGraph + fmt.Println("Call operation: GremlinResources_CreateUpdateGremlinGraph") + gremlinResourcesClient, err := armcosmos.NewGremlinResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + gremlinResourcesClientCreateUpdateGremlinGraphResponsePoller, err := gremlinResourcesClient.BeginCreateUpdateGremlinGraph(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.graphName, armcosmos.GremlinGraphCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.GremlinGraphCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{ + Throughput: to.Ptr[int32](2000), + }, + Resource: &armcosmos.GremlinGraphResource{ + ConflictResolutionPolicy: &armcosmos.ConflictResolutionPolicy{ + ConflictResolutionPath: to.Ptr("/path"), + Mode: to.Ptr(armcosmos.ConflictResolutionModeLastWriterWins), + }, + DefaultTTL: to.Ptr[int32](100), + ID: to.Ptr(testsuite.graphName), + IndexingPolicy: &armcosmos.IndexingPolicy{ + Automatic: to.Ptr(true), + ExcludedPaths: []*armcosmos.ExcludedPath{}, + IncludedPaths: []*armcosmos.IncludedPath{ + { + Path: to.Ptr("/*"), + Indexes: []*armcosmos.Indexes{ + { + DataType: to.Ptr(armcosmos.DataTypeString), + Kind: to.Ptr(armcosmos.IndexKindRange), + Precision: to.Ptr[int32](-1), + }, + { + DataType: to.Ptr(armcosmos.DataTypeNumber), + Kind: to.Ptr(armcosmos.IndexKindRange), + Precision: to.Ptr[int32](-1), + }}, + }}, + IndexingMode: to.Ptr(armcosmos.IndexingModeConsistent), + }, + PartitionKey: &armcosmos.ContainerPartitionKey{ + Kind: to.Ptr(armcosmos.PartitionKindHash), + Paths: []*string{ + to.Ptr("/AccountNumber")}, + }, + UniqueKeyPolicy: &armcosmos.UniqueKeyPolicy{ + UniqueKeys: []*armcosmos.UniqueKey{ + { + Paths: []*string{ + to.Ptr("/testPath")}, + }}, + }, + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, gremlinResourcesClientCreateUpdateGremlinGraphResponsePoller) + testsuite.Require().NoError(err) + + // From step GremlinResources_GetGremlinGraph + fmt.Println("Call operation: GremlinResources_GetGremlinGraph") + _, err = gremlinResourcesClient.GetGremlinGraph(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.graphName, nil) + testsuite.Require().NoError(err) + + // From step GremlinResources_GetGremlinGraphThroughput + fmt.Println("Call operation: GremlinResources_GetGremlinGraphThroughput") + _, err = gremlinResourcesClient.GetGremlinGraphThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.graphName, nil) + testsuite.Require().NoError(err) + + // From step GremlinResources_ListGremlinGraphs + fmt.Println("Call operation: GremlinResources_ListGremlinGraphs") + gremlinResourcesClientNewListGremlinGraphsPager := gremlinResourcesClient.NewListGremlinGraphsPager(testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + for gremlinResourcesClientNewListGremlinGraphsPager.More() { + _, err := gremlinResourcesClientNewListGremlinGraphsPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step GremlinResources_MigrateGremlinGraphToAutoscale + fmt.Println("Call operation: GremlinResources_MigrateGremlinGraphToAutoscale") + gremlinResourcesClientMigrateGremlinGraphToAutoscaleResponsePoller, err := gremlinResourcesClient.BeginMigrateGremlinGraphToAutoscale(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.graphName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, gremlinResourcesClientMigrateGremlinGraphToAutoscaleResponsePoller) + testsuite.Require().NoError(err) + + // From step GremlinResources_MigrateGremlinGraphToManualThroughput + fmt.Println("Call operation: GremlinResources_MigrateGremlinGraphToManualThroughput") + gremlinResourcesClientMigrateGremlinGraphToManualThroughputResponsePoller, err := gremlinResourcesClient.BeginMigrateGremlinGraphToManualThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.graphName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, gremlinResourcesClientMigrateGremlinGraphToManualThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step GremlinResources_UpdateGremlinGraphThroughput + fmt.Println("Call operation: GremlinResources_UpdateGremlinGraphThroughput") + gremlinResourcesClientUpdateGremlinGraphThroughputResponsePoller, err := gremlinResourcesClient.BeginUpdateGremlinGraphThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.graphName, armcosmos.ThroughputSettingsUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.ThroughputSettingsUpdateProperties{ + Resource: &armcosmos.ThroughputSettingsResource{ + Throughput: to.Ptr[int32](400), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, gremlinResourcesClientUpdateGremlinGraphThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step GremlinResources_DeleteGremlinGraph + fmt.Println("Call operation: GremlinResources_DeleteGremlinGraph") + gremlinResourcesClientDeleteGremlinGraphResponsePoller, err := gremlinResourcesClient.BeginDeleteGremlinGraph(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.graphName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, gremlinResourcesClientDeleteGremlinGraphResponsePoller) + testsuite.Require().NoError(err) +} + +func (testsuite *GremlinResourcesTestSuite) Cleanup() { + var err error + // From step GremlinResources_DeleteGremlinDatabase + fmt.Println("Call operation: GremlinResources_DeleteGremlinDatabase") + gremlinResourcesClient, err := armcosmos.NewGremlinResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + gremlinResourcesClientDeleteGremlinDatabaseResponsePoller, err := gremlinResourcesClient.BeginDeleteGremlinDatabase(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, gremlinResourcesClientDeleteGremlinDatabaseResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/cosmos/armcosmos/mongodbresources_live_test.go b/sdk/resourcemanager/cosmos/armcosmos/mongodbresources_live_test.go new file mode 100644 index 000000000000..bf4f8bbbab7c --- /dev/null +++ b/sdk/resourcemanager/cosmos/armcosmos/mongodbresources_live_test.go @@ -0,0 +1,256 @@ +//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 armcosmos_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/cosmos/armcosmos/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type MongoDbResourcesTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + accountName string + collectionName string + databaseName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *MongoDbResourcesTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmos/armcosmos/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.accountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "accountn", 14, true) + testsuite.collectionName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "collecti", 14, false) + testsuite.databaseName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "mongodb", 14, false) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + 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 *MongoDbResourcesTestSuite) 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 TestMongoDbResourcesTestSuite(t *testing.T) { + suite.Run(t, new(MongoDbResourcesTestSuite)) +} + +func (testsuite *MongoDbResourcesTestSuite) Prepare() { + var err error + // From step DatabaseAccounts_CreateOrUpdate + fmt.Println("Call operation: DatabaseAccounts_CreateOrUpdate") + databaseAccountsClient, err := armcosmos.NewDatabaseAccountsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + databaseAccountsClientCreateOrUpdateResponsePoller, err := databaseAccountsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.DatabaseAccountCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Kind: to.Ptr(armcosmos.DatabaseAccountKindMongoDB), + Properties: &armcosmos.DatabaseAccountCreateUpdateProperties{ + CreateMode: to.Ptr(armcosmos.CreateModeDefault), + DatabaseAccountOfferType: to.Ptr("Standard"), + Locations: []*armcosmos.Location{ + { + FailoverPriority: to.Ptr[int32](0), + IsZoneRedundant: to.Ptr(false), + LocationName: to.Ptr(testsuite.location), + }}, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step MongoDBResources_CreateUpdateMongoDBDatabase + fmt.Println("Call operation: MongoDBResources_CreateUpdateMongoDBDatabase") + mongoDBResourcesClient, err := armcosmos.NewMongoDBResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + mongoDBResourcesClientCreateUpdateMongoDBDatabaseResponsePoller, err := mongoDBResourcesClient.BeginCreateUpdateMongoDBDatabase(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, armcosmos.MongoDBDatabaseCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.MongoDBDatabaseCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{ + Throughput: to.Ptr[int32](2000), + }, + Resource: &armcosmos.MongoDBDatabaseResource{ + ID: to.Ptr(testsuite.databaseName), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, mongoDBResourcesClientCreateUpdateMongoDBDatabaseResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/mongodbDatabases/{databaseName} +func (testsuite *MongoDbResourcesTestSuite) TestMongoDbDatabase() { + var err error + // From step MongoDBResources_ListMongoDBDatabases + fmt.Println("Call operation: MongoDBResources_ListMongoDBDatabases") + mongoDBResourcesClient, err := armcosmos.NewMongoDBResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + mongoDBResourcesClientNewListMongoDBDatabasesPager := mongoDBResourcesClient.NewListMongoDBDatabasesPager(testsuite.resourceGroupName, testsuite.accountName, nil) + for mongoDBResourcesClientNewListMongoDBDatabasesPager.More() { + _, err := mongoDBResourcesClientNewListMongoDBDatabasesPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step MongoDBResources_GetMongoDBDatabase + fmt.Println("Call operation: MongoDBResources_GetMongoDBDatabase") + _, err = mongoDBResourcesClient.GetMongoDBDatabase(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + + // From step MongoDBResources_GetMongoDBDatabaseThroughput + fmt.Println("Call operation: MongoDBResources_GetMongoDBDatabaseThroughput") + _, err = mongoDBResourcesClient.GetMongoDBDatabaseThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + + // From step MongoDBResources_MigrateMongoDBDatabaseToAutoscale + fmt.Println("Call operation: MongoDBResources_MigrateMongoDBDatabaseToAutoscale") + mongoDBResourcesClientMigrateMongoDBDatabaseToAutoscaleResponsePoller, err := mongoDBResourcesClient.BeginMigrateMongoDBDatabaseToAutoscale(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, mongoDBResourcesClientMigrateMongoDBDatabaseToAutoscaleResponsePoller) + testsuite.Require().NoError(err) + + // From step MongoDBResources_MigrateMongoDBDatabaseToManualThroughput + fmt.Println("Call operation: MongoDBResources_MigrateMongoDBDatabaseToManualThroughput") + mongoDBResourcesClientMigrateMongoDBDatabaseToManualThroughputResponsePoller, err := mongoDBResourcesClient.BeginMigrateMongoDBDatabaseToManualThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, mongoDBResourcesClientMigrateMongoDBDatabaseToManualThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step MongoDBResources_UpdateMongoDBDatabaseThroughput + fmt.Println("Call operation: MongoDBResources_UpdateMongoDBDatabaseThroughput") + mongoDBResourcesClientUpdateMongoDBDatabaseThroughputResponsePoller, err := mongoDBResourcesClient.BeginUpdateMongoDBDatabaseThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, armcosmos.ThroughputSettingsUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.ThroughputSettingsUpdateProperties{ + Resource: &armcosmos.ThroughputSettingsResource{ + Throughput: to.Ptr[int32](400), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, mongoDBResourcesClientUpdateMongoDBDatabaseThroughputResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/mongodbDatabases/{databaseName}/collections/{collectionName} +func (testsuite *MongoDbResourcesTestSuite) TestMongoDbCollection() { + var err error + // From step MongoDBResources_CreateUpdateMongoDBCollection + fmt.Println("Call operation: MongoDBResources_CreateUpdateMongoDBCollection") + mongoDBResourcesClient, err := armcosmos.NewMongoDBResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + mongoDBResourcesClientCreateUpdateMongoDBCollectionResponsePoller, err := mongoDBResourcesClient.BeginCreateUpdateMongoDBCollection(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.collectionName, armcosmos.MongoDBCollectionCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.MongoDBCollectionCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{ + Throughput: to.Ptr[int32](2000), + }, + Resource: &armcosmos.MongoDBCollectionResource{ + ID: to.Ptr(testsuite.collectionName), + ShardKey: map[string]*string{ + "testKey": to.Ptr("Hash"), + }, + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, mongoDBResourcesClientCreateUpdateMongoDBCollectionResponsePoller) + testsuite.Require().NoError(err) + + // From step MongoDBResources_ListMongoDBCollections + fmt.Println("Call operation: MongoDBResources_ListMongoDBCollections") + mongoDBResourcesClientNewListMongoDBCollectionsPager := mongoDBResourcesClient.NewListMongoDBCollectionsPager(testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + for mongoDBResourcesClientNewListMongoDBCollectionsPager.More() { + _, err := mongoDBResourcesClientNewListMongoDBCollectionsPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step MongoDBResources_GetMongoDBCollection + fmt.Println("Call operation: MongoDBResources_GetMongoDBCollection") + _, err = mongoDBResourcesClient.GetMongoDBCollection(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.collectionName, nil) + testsuite.Require().NoError(err) + + // From step MongoDBResources_GetMongoDBCollectionThroughput + fmt.Println("Call operation: MongoDBResources_GetMongoDBCollectionThroughput") + _, err = mongoDBResourcesClient.GetMongoDBCollectionThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.collectionName, nil) + testsuite.Require().NoError(err) + + // From step MongoDBResources_MigrateMongoDBCollectionToAutoscale + fmt.Println("Call operation: MongoDBResources_MigrateMongoDBCollectionToAutoscale") + mongoDBResourcesClientMigrateMongoDBCollectionToAutoscaleResponsePoller, err := mongoDBResourcesClient.BeginMigrateMongoDBCollectionToAutoscale(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.collectionName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, mongoDBResourcesClientMigrateMongoDBCollectionToAutoscaleResponsePoller) + testsuite.Require().NoError(err) + + // From step MongoDBResources_MigrateMongoDBCollectionToManualThroughput + fmt.Println("Call operation: MongoDBResources_MigrateMongoDBCollectionToManualThroughput") + mongoDBResourcesClientMigrateMongoDBCollectionToManualThroughputResponsePoller, err := mongoDBResourcesClient.BeginMigrateMongoDBCollectionToManualThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.collectionName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, mongoDBResourcesClientMigrateMongoDBCollectionToManualThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step MongoDBResources_UpdateMongoDBCollectionThroughput + fmt.Println("Call operation: MongoDBResources_UpdateMongoDBCollectionThroughput") + mongoDBResourcesClientUpdateMongoDBCollectionThroughputResponsePoller, err := mongoDBResourcesClient.BeginUpdateMongoDBCollectionThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.collectionName, armcosmos.ThroughputSettingsUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.ThroughputSettingsUpdateProperties{ + Resource: &armcosmos.ThroughputSettingsResource{ + Throughput: to.Ptr[int32](400), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, mongoDBResourcesClientUpdateMongoDBCollectionThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step MongoDBResources_DeleteMongoDBCollection + fmt.Println("Call operation: MongoDBResources_DeleteMongoDBCollection") + mongoDBResourcesClientDeleteMongoDBCollectionResponsePoller, err := mongoDBResourcesClient.BeginDeleteMongoDBCollection(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.collectionName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, mongoDBResourcesClientDeleteMongoDBCollectionResponsePoller) + testsuite.Require().NoError(err) +} + +func (testsuite *MongoDbResourcesTestSuite) Cleanup() { + var err error + // From step MongoDBResources_DeleteMongoDBDatabase + fmt.Println("Call operation: MongoDBResources_DeleteMongoDBDatabase") + mongoDBResourcesClient, err := armcosmos.NewMongoDBResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + mongoDBResourcesClientDeleteMongoDBDatabaseResponsePoller, err := mongoDBResourcesClient.BeginDeleteMongoDBDatabase(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, mongoDBResourcesClientDeleteMongoDBDatabaseResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/cosmos/armcosmos/operations_live_test.go b/sdk/resourcemanager/cosmos/armcosmos/operations_live_test.go new file mode 100644 index 000000000000..adb91b40c504 --- /dev/null +++ b/sdk/resourcemanager/cosmos/armcosmos/operations_live_test.go @@ -0,0 +1,88 @@ +//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 armcosmos_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/cosmos/armcosmos/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type OperationsTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *OperationsTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmos/armcosmos/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + 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 *OperationsTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestOperationsTestSuite(t *testing.T) { + suite.Run(t, new(OperationsTestSuite)) +} + +// Microsoft.DocumentDB/operations +func (testsuite *OperationsTestSuite) TestOperations() { + var err error + // From step Operations_List + fmt.Println("Call operation: Operations_List") + operationsClient, err := armcosmos.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.DocumentDB/locations +func (testsuite *OperationsTestSuite) TestLocations() { + var err error + // From step Locations_List + fmt.Println("Call operation: Locations_List") + locationsClient, err := armcosmos.NewLocationsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + locationsClientNewListPager := locationsClient.NewListPager(nil) + for locationsClientNewListPager.More() { + _, err := locationsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Locations_Get + fmt.Println("Call operation: Locations_Get") + _, err = locationsClient.Get(testsuite.ctx, testsuite.location, nil) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/cosmos/armcosmos/privateendpointconnection_live_test.go b/sdk/resourcemanager/cosmos/armcosmos/privateendpointconnection_live_test.go new file mode 100644 index 000000000000..8d3c4a7819b7 --- /dev/null +++ b/sdk/resourcemanager/cosmos/armcosmos/privateendpointconnection_live_test.go @@ -0,0 +1,293 @@ +//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 armcosmos_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/cosmos/armcosmos/v2" + "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 PrivateEndpointConnectionTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + accountName string + cosmosAccountId string + privateEndpointConnectionName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *PrivateEndpointConnectionTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmos/armcosmos/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.accountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "accountn", 14, true) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + 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 *PrivateEndpointConnectionTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestPrivateEndpointConnectionTestSuite(t *testing.T) { + suite.Run(t, new(PrivateEndpointConnectionTestSuite)) +} + +func (testsuite *PrivateEndpointConnectionTestSuite) Prepare() { + var err error + // From step DatabaseAccounts_CreateOrUpdate + fmt.Println("Call operation: DatabaseAccounts_CreateOrUpdate") + databaseAccountsClient, err := armcosmos.NewDatabaseAccountsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + databaseAccountsClientCreateOrUpdateResponsePoller, err := databaseAccountsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.DatabaseAccountCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Properties: &armcosmos.DatabaseAccountCreateUpdateProperties{ + CreateMode: to.Ptr(armcosmos.CreateModeDefault), + DatabaseAccountOfferType: to.Ptr("Standard"), + Locations: []*armcosmos.Location{ + { + FailoverPriority: to.Ptr[int32](0), + IsZoneRedundant: to.Ptr(false), + LocationName: to.Ptr(testsuite.location), + }}, + }, + }, nil) + testsuite.Require().NoError(err) + var databaseAccountsClientCreateOrUpdateResponse *armcosmos.DatabaseAccountsClientCreateOrUpdateResponse + databaseAccountsClientCreateOrUpdateResponse, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + testsuite.cosmosAccountId = *databaseAccountsClientCreateOrUpdateResponse.ID + + // From step Create_PrivateEndpoint + 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{ + "privateEndpointConnectionName": map[string]any{ + "type": "string", + "value": "[parameters('privateEndpointName')]", + }, + }, + "parameters": map[string]any{ + "cosmosAccountId": map[string]any{ + "type": "string", + "defaultValue": testsuite.cosmosAccountId, + }, + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "networkInterfaceName": map[string]any{ + "type": "string", + "defaultValue": "epcosmos-nic", + }, + "privateEndpointName": map[string]any{ + "type": "string", + "defaultValue": "epcosmos", + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": "epcosmos-vnet", + }, + }, + "resources": []any{ + map[string]any{ + "name": "[parameters('virtualNetworksName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2020-11-01", + "location": "[parameters('location')]", + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ + "10.0.0.0/16", + }, + }, + "enableDdosProtection": false, + "subnets": []any{ + map[string]any{ + "name": "default", + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + "delegations": []any{}, + "privateEndpointNetworkPolicies": "Disabled", + "privateLinkServiceNetworkPolicies": "Enabled", + }, + }, + }, + "virtualNetworkPeerings": []any{}, + }, + }, + map[string]any{ + "name": "[parameters('networkInterfaceName')]", + "type": "Microsoft.Network/networkInterfaces", + "apiVersion": "2020-11-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + "location": "[parameters('location')]", + "properties": map[string]any{ + "dnsSettings": map[string]any{ + "dnsServers": []any{}, + }, + "enableIPForwarding": false, + "ipConfigurations": []any{ + map[string]any{ + "name": "privateEndpointIpConfig", + "properties": map[string]any{ + "primary": true, + "privateIPAddress": "10.0.0.4", + "privateIPAddressVersion": "IPv4", + "privateIPAllocationMethod": "Dynamic", + "subnet": map[string]any{ + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + }, + }, + }, + }, + }, + map[string]any{ + "name": "[parameters('privateEndpointName')]", + "type": "Microsoft.Network/privateEndpoints", + "apiVersion": "2020-11-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + "location": "[parameters('location')]", + "properties": map[string]any{ + "customDnsConfigs": []any{}, + "manualPrivateLinkServiceConnections": []any{}, + "privateLinkServiceConnections": []any{ + map[string]any{ + "name": "[parameters('privateEndpointName')]", + "properties": map[string]any{ + "groupIds": []any{ + "Sql", + }, + "privateLinkServiceConnectionState": map[string]any{ + "description": "Auto-Approved", + "actionsRequired": "None", + "status": "Approved", + }, + "privateLinkServiceId": "[parameters('cosmosAccountId')]", + }, + }, + }, + "subnet": map[string]any{ + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + }, + }, + map[string]any{ + "name": "[concat(parameters('virtualNetworksName'), '/default')]", + "type": "Microsoft.Network/virtualNetworks/subnets", + "apiVersion": "2020-11-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworksName'))]", + }, + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + "delegations": []any{}, + "privateEndpointNetworkPolicies": "Disabled", + "privateLinkServiceNetworkPolicies": "Enabled", + }, + }, + }, + "variables": 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_PrivateEndpoint", &deployment) + testsuite.Require().NoError(err) + testsuite.privateEndpointConnectionName = deploymentExtend.Properties.Outputs.(map[string]interface{})["privateEndpointConnectionName"].(map[string]interface{})["value"].(string) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/privateEndpointConnections/{privateEndpointConnectionName} +func (testsuite *PrivateEndpointConnectionTestSuite) TestPrivateEndpointConnections() { + var err error + // From step PrivateEndpointConnections_CreateOrUpdate + fmt.Println("Call operation: PrivateEndpointConnections_CreateOrUpdate") + privateEndpointConnectionsClient, err := armcosmos.NewPrivateEndpointConnectionsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + privateEndpointConnectionsClientCreateOrUpdateResponsePoller, err := privateEndpointConnectionsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.privateEndpointConnectionName, armcosmos.PrivateEndpointConnection{ + Properties: &armcosmos.PrivateEndpointConnectionProperties{ + GroupID: to.Ptr("Sql"), + PrivateLinkServiceConnectionState: &armcosmos.PrivateLinkServiceConnectionStateProperty{ + Description: to.Ptr("Approved by johndoe@contoso.com"), + Status: to.Ptr("Approved"), + }, + ProvisioningState: to.Ptr("Succeeded"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, privateEndpointConnectionsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step PrivateEndpointConnections_ListByDatabaseAccount + fmt.Println("Call operation: PrivateEndpointConnections_ListByDatabaseAccount") + privateEndpointConnectionsClientNewListByDatabaseAccountPager := privateEndpointConnectionsClient.NewListByDatabaseAccountPager(testsuite.resourceGroupName, testsuite.accountName, nil) + for privateEndpointConnectionsClientNewListByDatabaseAccountPager.More() { + _, err := privateEndpointConnectionsClientNewListByDatabaseAccountPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step PrivateEndpointConnections_Get + fmt.Println("Call operation: PrivateEndpointConnections_Get") + _, err = privateEndpointConnectionsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.privateEndpointConnectionName, nil) + testsuite.Require().NoError(err) + + // From step PrivateLinkResources_ListByDatabaseAccount + fmt.Println("Call operation: PrivateLinkResources_ListByDatabaseAccount") + privateLinkResourcesClient, err := armcosmos.NewPrivateLinkResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + privateLinkResourcesClientNewListByDatabaseAccountPager := privateLinkResourcesClient.NewListByDatabaseAccountPager(testsuite.resourceGroupName, testsuite.accountName, nil) + for privateLinkResourcesClientNewListByDatabaseAccountPager.More() { + _, err := privateLinkResourcesClientNewListByDatabaseAccountPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step PrivateLinkResources_Get + fmt.Println("Call operation: PrivateLinkResources_Get") + _, err = privateLinkResourcesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, "sql", nil) + testsuite.Require().NoError(err) + + // From step PrivateEndpointConnections_Delete + fmt.Println("Call operation: PrivateEndpointConnections_Delete") + privateEndpointConnectionsClientDeleteResponsePoller, err := privateEndpointConnectionsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.privateEndpointConnectionName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, privateEndpointConnectionsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/cosmos/armcosmos/services_live_test.go b/sdk/resourcemanager/cosmos/armcosmos/services_live_test.go new file mode 100644 index 000000000000..0e5922b8ce43 --- /dev/null +++ b/sdk/resourcemanager/cosmos/armcosmos/services_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. + +package armcosmos_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/cosmos/armcosmos/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type ServicesTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + accountName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *ServicesTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmos/armcosmos/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.accountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "accountn", 14, true) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + 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 *ServicesTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestServicesTestSuite(t *testing.T) { + suite.Run(t, new(ServicesTestSuite)) +} + +func (testsuite *ServicesTestSuite) Prepare() { + var err error + // From step DatabaseAccounts_CreateOrUpdate + fmt.Println("Call operation: DatabaseAccounts_CreateOrUpdate") + databaseAccountsClient, err := armcosmos.NewDatabaseAccountsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + databaseAccountsClientCreateOrUpdateResponsePoller, err := databaseAccountsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.DatabaseAccountCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Properties: &armcosmos.DatabaseAccountCreateUpdateProperties{ + CreateMode: to.Ptr(armcosmos.CreateModeDefault), + DatabaseAccountOfferType: to.Ptr("Standard"), + Locations: []*armcosmos.Location{ + { + FailoverPriority: to.Ptr[int32](0), + IsZoneRedundant: to.Ptr(false), + LocationName: to.Ptr(testsuite.location), + }}, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/services/{serviceName} +func (testsuite *ServicesTestSuite) TestService() { + var err error + // From step Service_Create + fmt.Println("Call operation: Service_Create") + serviceClient, err := armcosmos.NewServiceClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + serviceClientCreateResponsePoller, err := serviceClient.BeginCreate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, "SqlDedicatedGateway", armcosmos.ServiceResourceCreateUpdateParameters{ + Properties: &armcosmos.ServiceResourceCreateUpdateProperties{ + InstanceCount: to.Ptr[int32](1), + InstanceSize: to.Ptr(armcosmos.ServiceSizeCosmosD4S), + ServiceType: to.Ptr(armcosmos.ServiceTypeSQLDedicatedGateway), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, serviceClientCreateResponsePoller) + testsuite.Require().NoError(err) + + // From step Service_List + fmt.Println("Call operation: Service_List") + serviceClientNewListPager := serviceClient.NewListPager(testsuite.resourceGroupName, testsuite.accountName, nil) + for serviceClientNewListPager.More() { + _, err := serviceClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Service_Get + fmt.Println("Call operation: Service_Get") + _, err = serviceClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, "SqlDedicatedGateway", nil) + testsuite.Require().NoError(err) + + // From step Service_Delete + fmt.Println("Call operation: Service_Delete") + serviceClientDeleteResponsePoller, err := serviceClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, "SqlDedicatedGateway", nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, serviceClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/cosmos/armcosmos/sqlresources_live_test.go b/sdk/resourcemanager/cosmos/armcosmos/sqlresources_live_test.go new file mode 100644 index 000000000000..0de386832bb0 --- /dev/null +++ b/sdk/resourcemanager/cosmos/armcosmos/sqlresources_live_test.go @@ -0,0 +1,465 @@ +//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 armcosmos_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/cosmos/armcosmos/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type SqlResourcesTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + accountName string + containerName string + databaseName string + triggerName string + storedProcedureName string + userDefinedFunctionName string + clientEncryptionKeyName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *SqlResourcesTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmos/armcosmos/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.accountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "accountn", 14, true) + testsuite.containerName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "sqlcontaine", 17, false) + testsuite.databaseName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "sqldb", 11, false) + testsuite.triggerName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "triggern", 14, false) + testsuite.storedProcedureName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "storedpr", 14, true) + testsuite.userDefinedFunctionName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "userdefi", 14, false) + testsuite.clientEncryptionKeyName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "clienten", 14, false) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + 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 *SqlResourcesTestSuite) 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 TestSqlResourcesTestSuite(t *testing.T) { + suite.Run(t, new(SqlResourcesTestSuite)) +} + +func (testsuite *SqlResourcesTestSuite) Prepare() { + var err error + // From step DatabaseAccounts_CreateOrUpdate + fmt.Println("Call operation: DatabaseAccounts_CreateOrUpdate") + databaseAccountsClient, err := armcosmos.NewDatabaseAccountsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + databaseAccountsClientCreateOrUpdateResponsePoller, err := databaseAccountsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.DatabaseAccountCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Properties: &armcosmos.DatabaseAccountCreateUpdateProperties{ + CreateMode: to.Ptr(armcosmos.CreateModeDefault), + DatabaseAccountOfferType: to.Ptr("Standard"), + Locations: []*armcosmos.Location{ + { + FailoverPriority: to.Ptr[int32](0), + IsZoneRedundant: to.Ptr(false), + LocationName: to.Ptr(testsuite.location), + }}, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_CreateUpdateSqlDatabase + fmt.Println("Call operation: SQLResources_CreateUpdateSQLDatabase") + sQLResourcesClient, err := armcosmos.NewSQLResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + sQLResourcesClientCreateUpdateSQLDatabaseResponsePoller, err := sQLResourcesClient.BeginCreateUpdateSQLDatabase(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, armcosmos.SQLDatabaseCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.SQLDatabaseCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{ + Throughput: to.Ptr[int32](2000), + }, + Resource: &armcosmos.SQLDatabaseResource{ + ID: to.Ptr(testsuite.databaseName), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientCreateUpdateSQLDatabaseResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_CreateUpdateSqlContainer + fmt.Println("Call operation: SQLResources_CreateUpdateSQLContainer") + sQLResourcesClientCreateUpdateSQLContainerResponsePoller, err := sQLResourcesClient.BeginCreateUpdateSQLContainer(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, armcosmos.SQLContainerCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.SQLContainerCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{ + Throughput: to.Ptr[int32](2000), + }, + Resource: &armcosmos.SQLContainerResource{ + ConflictResolutionPolicy: &armcosmos.ConflictResolutionPolicy{ + ConflictResolutionPath: to.Ptr("/path"), + Mode: to.Ptr(armcosmos.ConflictResolutionModeLastWriterWins), + }, + ID: to.Ptr(testsuite.containerName), + IndexingPolicy: &armcosmos.IndexingPolicy{ + Automatic: to.Ptr(true), + ExcludedPaths: []*armcosmos.ExcludedPath{}, + IncludedPaths: []*armcosmos.IncludedPath{ + { + Path: to.Ptr("/*"), + Indexes: []*armcosmos.Indexes{ + { + DataType: to.Ptr(armcosmos.DataTypeString), + Kind: to.Ptr(armcosmos.IndexKindRange), + Precision: to.Ptr[int32](-1), + }, + { + DataType: to.Ptr(armcosmos.DataTypeNumber), + Kind: to.Ptr(armcosmos.IndexKindRange), + Precision: to.Ptr[int32](-1), + }}, + }}, + IndexingMode: to.Ptr(armcosmos.IndexingModeConsistent), + }, + PartitionKey: &armcosmos.ContainerPartitionKey{ + Kind: to.Ptr(armcosmos.PartitionKindHash), + Paths: []*string{ + to.Ptr("/AccountNumber")}, + }, + UniqueKeyPolicy: &armcosmos.UniqueKeyPolicy{ + UniqueKeys: []*armcosmos.UniqueKey{ + { + Paths: []*string{ + to.Ptr("/testPath")}, + }}, + }, + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientCreateUpdateSQLContainerResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/sqlDatabases/{databaseName} +func (testsuite *SqlResourcesTestSuite) TestSqlDatabase() { + var err error + // From step SqlResources_ListSqlDatabases + fmt.Println("Call operation: SQLResources_ListSQLDatabases") + sQLResourcesClient, err := armcosmos.NewSQLResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + sQLResourcesClientNewListSQLDatabasesPager := sQLResourcesClient.NewListSQLDatabasesPager(testsuite.resourceGroupName, testsuite.accountName, nil) + for sQLResourcesClientNewListSQLDatabasesPager.More() { + _, err := sQLResourcesClientNewListSQLDatabasesPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step SqlResources_GetSqlDatabase + fmt.Println("Call operation: SQLResources_GetSQLDatabase") + _, err = sQLResourcesClient.GetSQLDatabase(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + + // From step SqlResources_GetSqlDatabaseThroughput + fmt.Println("Call operation: SQLResources_GetSQLDatabaseThroughput") + _, err = sQLResourcesClient.GetSQLDatabaseThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + + // From step SqlResources_UpdateSqlDatabaseThroughput + fmt.Println("Call operation: SQLResources_UpdateSQLDatabaseThroughput") + sQLResourcesClientUpdateSQLDatabaseThroughputResponsePoller, err := sQLResourcesClient.BeginUpdateSQLDatabaseThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, armcosmos.ThroughputSettingsUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.ThroughputSettingsUpdateProperties{ + Resource: &armcosmos.ThroughputSettingsResource{ + Throughput: to.Ptr[int32](400), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientUpdateSQLDatabaseThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_MigrateSqlDatabaseToAutoscale + fmt.Println("Call operation: SQLResources_MigrateSQLDatabaseToAutoscale") + sQLResourcesClientMigrateSQLDatabaseToAutoscaleResponsePoller, err := sQLResourcesClient.BeginMigrateSQLDatabaseToAutoscale(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientMigrateSQLDatabaseToAutoscaleResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_MigrateSqlDatabaseToManualThroughput + fmt.Println("Call operation: SQLResources_MigrateSQLDatabaseToManualThroughput") + sQLResourcesClientMigrateSQLDatabaseToManualThroughputResponsePoller, err := sQLResourcesClient.BeginMigrateSQLDatabaseToManualThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientMigrateSQLDatabaseToManualThroughputResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/sqlDatabases/{databaseName}/containers/{containerName} +func (testsuite *SqlResourcesTestSuite) TestSqlContainer() { + var err error + // From step SqlResources_GetSqlContainer + fmt.Println("Call operation: SQLResources_GetSQLContainer") + sQLResourcesClient, err := armcosmos.NewSQLResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = sQLResourcesClient.GetSQLContainer(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, nil) + testsuite.Require().NoError(err) + + // From step SqlResources_ListSqlContainers + fmt.Println("Call operation: SQLResources_ListSQLContainers") + sQLResourcesClientNewListSQLContainersPager := sQLResourcesClient.NewListSQLContainersPager(testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + for sQLResourcesClientNewListSQLContainersPager.More() { + _, err := sQLResourcesClientNewListSQLContainersPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step SqlResources_GetSqlContainerThroughput + fmt.Println("Call operation: SQLResources_GetSQLContainerThroughput") + _, err = sQLResourcesClient.GetSQLContainerThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, nil) + testsuite.Require().NoError(err) + + // From step SqlResources_UpdateSqlContainerThroughput + fmt.Println("Call operation: SQLResources_UpdateSQLContainerThroughput") + sQLResourcesClientUpdateSQLContainerThroughputResponsePoller, err := sQLResourcesClient.BeginUpdateSQLContainerThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, armcosmos.ThroughputSettingsUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.ThroughputSettingsUpdateProperties{ + Resource: &armcosmos.ThroughputSettingsResource{ + Throughput: to.Ptr[int32](400), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientUpdateSQLContainerThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_MigrateSqlContainerToAutoscale + fmt.Println("Call operation: SQLResources_MigrateSQLContainerToAutoscale") + sQLResourcesClientMigrateSQLContainerToAutoscaleResponsePoller, err := sQLResourcesClient.BeginMigrateSQLContainerToAutoscale(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientMigrateSQLContainerToAutoscaleResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_MigrateSqlContainerToManualThroughput + fmt.Println("Call operation: SQLResources_MigrateSQLContainerToManualThroughput") + sQLResourcesClientMigrateSQLContainerToManualThroughputResponsePoller, err := sQLResourcesClient.BeginMigrateSQLContainerToManualThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientMigrateSQLContainerToManualThroughputResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/sqlDatabases/{databaseName}/containers/{containerName}/triggers/{triggerName} +func (testsuite *SqlResourcesTestSuite) TestSqlTrigger() { + var err error + // From step SqlResources_CreateUpdateSqlTrigger + fmt.Println("Call operation: SQLResources_CreateUpdateSQLTrigger") + sQLResourcesClient, err := armcosmos.NewSQLResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + sQLResourcesClientCreateUpdateSQLTriggerResponsePoller, err := sQLResourcesClient.BeginCreateUpdateSQLTrigger(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, testsuite.triggerName, armcosmos.SQLTriggerCreateUpdateParameters{ + Properties: &armcosmos.SQLTriggerCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{}, + Resource: &armcosmos.SQLTriggerResource{ + Body: to.Ptr("body"), + ID: to.Ptr(testsuite.triggerName), + TriggerOperation: to.Ptr(armcosmos.TriggerOperationAll), + TriggerType: to.Ptr(armcosmos.TriggerTypePre), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientCreateUpdateSQLTriggerResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_GetSqlTrigger + fmt.Println("Call operation: SQLResources_GetSQLTrigger") + _, err = sQLResourcesClient.GetSQLTrigger(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, testsuite.triggerName, nil) + testsuite.Require().NoError(err) + + // From step SqlResources_ListSqlTriggers + fmt.Println("Call operation: SQLResources_ListSQLTriggers") + sQLResourcesClientNewListSQLTriggersPager := sQLResourcesClient.NewListSQLTriggersPager(testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, nil) + for sQLResourcesClientNewListSQLTriggersPager.More() { + _, err := sQLResourcesClientNewListSQLTriggersPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step SqlResources_DeleteSqlTrigger + fmt.Println("Call operation: SQLResources_DeleteSQLTrigger") + sQLResourcesClientDeleteSQLTriggerResponsePoller, err := sQLResourcesClient.BeginDeleteSQLTrigger(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, testsuite.triggerName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientDeleteSQLTriggerResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/sqlDatabases/{databaseName}/containers/{containerName}/storedProcedures/{storedProcedureName} +func (testsuite *SqlResourcesTestSuite) TestSqlStoredProcedure() { + var err error + // From step SqlResources_CreateUpdateSqlStoredProcedure + fmt.Println("Call operation: SQLResources_CreateUpdateSQLStoredProcedure") + sQLResourcesClient, err := armcosmos.NewSQLResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + sQLResourcesClientCreateUpdateSQLStoredProcedureResponsePoller, err := sQLResourcesClient.BeginCreateUpdateSQLStoredProcedure(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, testsuite.storedProcedureName, armcosmos.SQLStoredProcedureCreateUpdateParameters{ + Properties: &armcosmos.SQLStoredProcedureCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{}, + Resource: &armcosmos.SQLStoredProcedureResource{ + Body: to.Ptr("body"), + ID: to.Ptr(testsuite.storedProcedureName), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientCreateUpdateSQLStoredProcedureResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_GetSqlStoredProcedure + fmt.Println("Call operation: SQLResources_GetSQLStoredProcedure") + _, err = sQLResourcesClient.GetSQLStoredProcedure(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, testsuite.storedProcedureName, nil) + testsuite.Require().NoError(err) + + // From step SqlResources_ListSqlStoredProcedures + fmt.Println("Call operation: SQLResources_ListSQLStoredProcedures") + sQLResourcesClientNewListSQLStoredProceduresPager := sQLResourcesClient.NewListSQLStoredProceduresPager(testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, nil) + for sQLResourcesClientNewListSQLStoredProceduresPager.More() { + _, err := sQLResourcesClientNewListSQLStoredProceduresPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step SqlResources_DeleteSqlStoredProcedure + fmt.Println("Call operation: SQLResources_DeleteSQLStoredProcedure") + sQLResourcesClientDeleteSQLStoredProcedureResponsePoller, err := sQLResourcesClient.BeginDeleteSQLStoredProcedure(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, testsuite.storedProcedureName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientDeleteSQLStoredProcedureResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/sqlDatabases/{databaseName}/containers/{containerName}/userDefinedFunctions/{userDefinedFunctionName} +func (testsuite *SqlResourcesTestSuite) TestSqlUserDefinedFunction() { + var err error + // From step SqlResources_CreateUpdateSqlUserDefinedFunction + fmt.Println("Call operation: SQLResources_CreateUpdateSQLUserDefinedFunction") + sQLResourcesClient, err := armcosmos.NewSQLResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + sQLResourcesClientCreateUpdateSQLUserDefinedFunctionResponsePoller, err := sQLResourcesClient.BeginCreateUpdateSQLUserDefinedFunction(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, testsuite.userDefinedFunctionName, armcosmos.SQLUserDefinedFunctionCreateUpdateParameters{ + Properties: &armcosmos.SQLUserDefinedFunctionCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{}, + Resource: &armcosmos.SQLUserDefinedFunctionResource{ + Body: to.Ptr("body"), + ID: to.Ptr(testsuite.userDefinedFunctionName), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientCreateUpdateSQLUserDefinedFunctionResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_GetSqlUserDefinedFunction + fmt.Println("Call operation: SQLResources_GetSQLUserDefinedFunction") + _, err = sQLResourcesClient.GetSQLUserDefinedFunction(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, testsuite.userDefinedFunctionName, nil) + testsuite.Require().NoError(err) + + // From step SqlResources_ListSqlUserDefinedFunctions + fmt.Println("Call operation: SQLResources_ListSQLUserDefinedFunctions") + sQLResourcesClientNewListSQLUserDefinedFunctionsPager := sQLResourcesClient.NewListSQLUserDefinedFunctionsPager(testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, nil) + for sQLResourcesClientNewListSQLUserDefinedFunctionsPager.More() { + _, err := sQLResourcesClientNewListSQLUserDefinedFunctionsPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step SqlResources_DeleteSqlUserDefinedFunction + fmt.Println("Call operation: SQLResources_DeleteSQLUserDefinedFunction") + sQLResourcesClientDeleteSQLUserDefinedFunctionResponsePoller, err := sQLResourcesClient.BeginDeleteSQLUserDefinedFunction(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, testsuite.userDefinedFunctionName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientDeleteSQLUserDefinedFunctionResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/sqlDatabases/{databaseName}/clientEncryptionKeys/{clientEncryptionKeyName} +func (testsuite *SqlResourcesTestSuite) TestSqlClientEncryptionKey() { + var err error + // From step SqlResources_CreateUpdateClientEncryptionKey + fmt.Println("Call operation: SQLResources_CreateUpdateClientEncryptionKey") + sQLResourcesClient, err := armcosmos.NewSQLResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + sQLResourcesClientCreateUpdateClientEncryptionKeyResponsePoller, err := sQLResourcesClient.BeginCreateUpdateClientEncryptionKey(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.clientEncryptionKeyName, armcosmos.ClientEncryptionKeyCreateUpdateParameters{ + Properties: &armcosmos.ClientEncryptionKeyCreateUpdateProperties{ + Resource: &armcosmos.ClientEncryptionKeyResource{ + EncryptionAlgorithm: to.Ptr("AEAD_AES_256_CBC_HMAC_SHA256"), + ID: to.Ptr(testsuite.clientEncryptionKeyName), + KeyWrapMetadata: &armcosmos.KeyWrapMetadata{ + Name: to.Ptr("customerManagedKey"), + Type: to.Ptr("AzureKeyVault"), + Algorithm: to.Ptr("RSA-OAEP"), + Value: to.Ptr("AzureKeyVault Key URL"), + }, + WrappedDataEncryptionKey: []byte("U3dhZ2dlciByb2Nrcw=="), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientCreateUpdateClientEncryptionKeyResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_GetClientEncryptionKey + fmt.Println("Call operation: SQLResources_GetClientEncryptionKey") + _, err = sQLResourcesClient.GetClientEncryptionKey(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.clientEncryptionKeyName, nil) + testsuite.Require().NoError(err) + + // From step SqlResources_ListClientEncryptionKeys + fmt.Println("Call operation: SQLResources_ListClientEncryptionKeys") + sQLResourcesClientNewListClientEncryptionKeysPager := sQLResourcesClient.NewListClientEncryptionKeysPager(testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + for sQLResourcesClientNewListClientEncryptionKeysPager.More() { + _, err := sQLResourcesClientNewListClientEncryptionKeysPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} + +func (testsuite *SqlResourcesTestSuite) Cleanup() { + var err error + // From step SqlResources_DeleteSqlContainer + fmt.Println("Call operation: SQLResources_DeleteSQLContainer") + sQLResourcesClient, err := armcosmos.NewSQLResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + sQLResourcesClientDeleteSQLContainerResponsePoller, err := sQLResourcesClient.BeginDeleteSQLContainer(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, testsuite.containerName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientDeleteSQLContainerResponsePoller) + testsuite.Require().NoError(err) + + // From step SqlResources_DeleteSqlDatabase + fmt.Println("Call operation: SQLResources_DeleteSQLDatabase") + sQLResourcesClientDeleteSQLDatabaseResponsePoller, err := sQLResourcesClient.BeginDeleteSQLDatabase(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.databaseName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, sQLResourcesClientDeleteSQLDatabaseResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/cosmos/armcosmos/tableresources_live_test.go b/sdk/resourcemanager/cosmos/armcosmos/tableresources_live_test.go new file mode 100644 index 000000000000..3f72a33f3c5f --- /dev/null +++ b/sdk/resourcemanager/cosmos/armcosmos/tableresources_live_test.go @@ -0,0 +1,166 @@ +//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 armcosmos_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/cosmos/armcosmos/v2" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type TableResourcesTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + accountName string + tableName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *TableResourcesTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmos/armcosmos/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.accountName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "accountn", 14, true) + testsuite.tableName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "tablenam", 14, false) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + 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 *TableResourcesTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestTableResourcesTestSuite(t *testing.T) { + suite.Run(t, new(TableResourcesTestSuite)) +} + +func (testsuite *TableResourcesTestSuite) Prepare() { + var err error + // From step DatabaseAccounts_CreateOrUpdate + fmt.Println("Call operation: DatabaseAccounts_CreateOrUpdate") + databaseAccountsClient, err := armcosmos.NewDatabaseAccountsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + databaseAccountsClientCreateOrUpdateResponsePoller, err := databaseAccountsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, armcosmos.DatabaseAccountCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Kind: to.Ptr(armcosmos.DatabaseAccountKindGlobalDocumentDB), + Properties: &armcosmos.DatabaseAccountCreateUpdateProperties{ + Capabilities: []*armcosmos.Capability{ + { + Name: to.Ptr("EnableTable"), + }}, + CreateMode: to.Ptr(armcosmos.CreateModeDefault), + DatabaseAccountOfferType: to.Ptr("Standard"), + Locations: []*armcosmos.Location{ + { + FailoverPriority: to.Ptr[int32](0), + IsZoneRedundant: to.Ptr(false), + LocationName: to.Ptr(testsuite.location), + }}, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, databaseAccountsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DocumentDB/databaseAccounts/{accountName}/tables/{tableName} +func (testsuite *TableResourcesTestSuite) TestTableResources() { + var err error + // From step TableResources_CreateUpdateTable + fmt.Println("Call operation: TableResources_CreateUpdateTable") + tableResourcesClient, err := armcosmos.NewTableResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + tableResourcesClientCreateUpdateTableResponsePoller, err := tableResourcesClient.BeginCreateUpdateTable(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.tableName, armcosmos.TableCreateUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.TableCreateUpdateProperties{ + Options: &armcosmos.CreateUpdateOptions{}, + Resource: &armcosmos.TableResource{ + ID: to.Ptr(testsuite.tableName), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, tableResourcesClientCreateUpdateTableResponsePoller) + testsuite.Require().NoError(err) + + // From step TableResources_ListTables + fmt.Println("Call operation: TableResources_ListTables") + tableResourcesClientNewListTablesPager := tableResourcesClient.NewListTablesPager(testsuite.resourceGroupName, testsuite.accountName, nil) + for tableResourcesClientNewListTablesPager.More() { + _, err := tableResourcesClientNewListTablesPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step TableResources_GetTableThroughput + fmt.Println("Call operation: TableResources_GetTableThroughput") + _, err = tableResourcesClient.GetTableThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.tableName, nil) + testsuite.Require().NoError(err) + + // From step TableResources_GetTable + fmt.Println("Call operation: TableResources_GetTable") + _, err = tableResourcesClient.GetTable(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.tableName, nil) + testsuite.Require().NoError(err) + + // From step TableResources_MigrateTableToAutoscale + fmt.Println("Call operation: TableResources_MigrateTableToAutoscale") + tableResourcesClientMigrateTableToAutoscaleResponsePoller, err := tableResourcesClient.BeginMigrateTableToAutoscale(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.tableName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, tableResourcesClientMigrateTableToAutoscaleResponsePoller) + testsuite.Require().NoError(err) + + // From step TableResources_MigrateTableToManualThroughput + fmt.Println("Call operation: TableResources_MigrateTableToManualThroughput") + tableResourcesClientMigrateTableToManualThroughputResponsePoller, err := tableResourcesClient.BeginMigrateTableToManualThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.tableName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, tableResourcesClientMigrateTableToManualThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step TableResources_UpdateTableThroughput + fmt.Println("Call operation: TableResources_UpdateTableThroughput") + tableResourcesClientUpdateTableThroughputResponsePoller, err := tableResourcesClient.BeginUpdateTableThroughput(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.tableName, armcosmos.ThroughputSettingsUpdateParameters{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmos.ThroughputSettingsUpdateProperties{ + Resource: &armcosmos.ThroughputSettingsResource{ + Throughput: to.Ptr[int32](400), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, tableResourcesClientUpdateTableThroughputResponsePoller) + testsuite.Require().NoError(err) + + // From step TableResources_DeleteTable + fmt.Println("Call operation: TableResources_DeleteTable") + tableResourcesClientDeleteTableResponsePoller, err := tableResourcesClient.BeginDeleteTable(testsuite.ctx, testsuite.resourceGroupName, testsuite.accountName, testsuite.tableName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, tableResourcesClientDeleteTableResponsePoller) + testsuite.Require().NoError(err) +}