From af77b419355ae46012f1dbae75464aa6a4e11519 Mon Sep 17 00:00:00 2001 From: Serge Smertin Date: Mon, 26 Jun 2023 14:26:07 -0700 Subject: [PATCH] Expose `debug-env.json` wrappers through `qa` package --- internal/acceptance_test.go | 21 ++++---- internal/billing_test.go | 21 ++++---- internal/catalog_test.go | 83 +++++++++++++++-------------- internal/clusterpolicies_test.go | 7 +-- internal/clusters_test.go | 21 ++++---- internal/commands_test.go | 9 ++-- internal/dbsql_test.go | 19 +++---- internal/deployment_test.go | 65 +++++++++++----------- internal/files_test.go | 27 +++++----- internal/git_credentials_test.go | 7 +-- internal/globalinitscripts_test.go | 7 +-- internal/instancepools_test.go | 7 +-- internal/ipaccesslists_test.go | 7 +-- internal/jobs_test.go | 21 ++++---- internal/libraries_test.go | 3 +- internal/mlflow_test.go | 37 ++++++------- internal/permissions_test.go | 13 ++--- internal/pipelines_test.go | 11 ++-- internal/repos_test.go | 5 +- internal/scim_test.go | 19 +++---- internal/secrets_test.go | 11 ++-- internal/sharing_test.go | 29 +++++----- internal/tokenmanagement_test.go | 5 +- internal/tokens_test.go | 5 +- internal/warehouses_test.go | 7 +-- internal/workspace_test.go | 21 ++++---- internal/workspaceconf_test.go | 3 +- internal/init_test.go => qa/init.go | 18 +++---- 28 files changed, 268 insertions(+), 241 deletions(-) rename internal/init_test.go => qa/init.go (89%) diff --git a/internal/acceptance_test.go b/internal/acceptance_test.go index 9b13bbc33..b00101368 100644 --- a/internal/acceptance_test.go +++ b/internal/acceptance_test.go @@ -8,13 +8,14 @@ import ( "github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go/config" "github.com/databricks/databricks-sdk-go/internal/env" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccDefaultCredentials(t *testing.T) { - t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) + t.Log(qa.GetEnvOrSkipTest(t, "CLOUD_ENV")) w := databricks.Must(databricks.NewWorkspaceClient()) if w.Config.IsAccountClient() { t.SkipNow() @@ -35,7 +36,7 @@ func TestAccDefaultCredentials(t *testing.T) { func TestAccExplicitDatabricksCfg(t *testing.T) { w := databricks.Must(databricks.NewWorkspaceClient(&databricks.Config{ - Profile: GetEnvOrSkipTest(t, "DATABRICKS_CONFIG_PROFILE"), + Profile: qa.GetEnvOrSkipTest(t, "DATABRICKS_CONFIG_PROFILE"), })) if w.Config.IsAccountClient() { t.SkipNow() @@ -62,9 +63,9 @@ func TestAccExplicitAzureCliAuth(t *testing.T) { "az", "login", "--service-principal", - "--user", GetEnvOrSkipTest(t, "ARM_CLIENT_ID"), - "--password", GetEnvOrSkipTest(t, "ARM_CLIENT_SECRET"), - "--tenant", GetEnvOrSkipTest(t, "ARM_TENANT_ID"), + "--user", qa.GetEnvOrSkipTest(t, "ARM_CLIENT_ID"), + "--password", qa.GetEnvOrSkipTest(t, "ARM_CLIENT_SECRET"), + "--tenant", qa.GetEnvOrSkipTest(t, "ARM_TENANT_ID"), ) out, err := cmd.Output() if err != nil { @@ -72,7 +73,7 @@ func TestAccExplicitAzureCliAuth(t *testing.T) { } w := databricks.Must(databricks.NewWorkspaceClient(&databricks.Config{ - AzureResourceID: GetEnvOrSkipTest(t, "DATABRICKS_AZURE_RESOURCE_ID"), + AzureResourceID: qa.GetEnvOrSkipTest(t, "DATABRICKS_AZURE_RESOURCE_ID"), Credentials: config.AzureCliCredentials{}, })) ctx := context.Background() @@ -89,10 +90,10 @@ func TestAccExplicitAzureCliAuth(t *testing.T) { func TestAccExplicitAzureSpnAuth(t *testing.T) { w := databricks.Must(databricks.NewWorkspaceClient(&databricks.Config{ - AzureTenantID: GetEnvOrSkipTest(t, "ARM_TENANT_ID"), - AzureClientID: GetEnvOrSkipTest(t, "ARM_CLIENT_ID"), - AzureClientSecret: GetEnvOrSkipTest(t, "ARM_CLIENT_SECRET"), - AzureResourceID: GetEnvOrSkipTest(t, "DATABRICKS_AZURE_RESOURCE_ID"), + AzureTenantID: qa.GetEnvOrSkipTest(t, "ARM_TENANT_ID"), + AzureClientID: qa.GetEnvOrSkipTest(t, "ARM_CLIENT_ID"), + AzureClientSecret: qa.GetEnvOrSkipTest(t, "ARM_CLIENT_SECRET"), + AzureResourceID: qa.GetEnvOrSkipTest(t, "DATABRICKS_AZURE_RESOURCE_ID"), Credentials: config.AzureClientSecretCredentials{}, })) ctx := context.Background() diff --git a/internal/billing_test.go b/internal/billing_test.go index d1d6f2700..152346a3a 100644 --- a/internal/billing_test.go +++ b/internal/billing_test.go @@ -3,6 +3,7 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/billing" "github.com/databricks/databricks-sdk-go/service/provisioning" "github.com/stretchr/testify/assert" @@ -10,7 +11,7 @@ import ( ) func TestMwsAccUsageDownload(t *testing.T) { - ctx, a := accountTest(t) + ctx, a := qa.AccountTest(t) if !a.Config.IsAws() { t.SkipNow() } @@ -23,15 +24,15 @@ func TestMwsAccUsageDownload(t *testing.T) { } func TestMwsAccLogDelivery(t *testing.T) { - ctx, a := accountTest(t) + ctx, a := qa.AccountTest(t) if !a.Config.IsAws() { t.SkipNow() } creds, err := a.Credentials.Create(ctx, provisioning.CreateCredentialRequest{ - CredentialsName: RandomName("sdk-"), + CredentialsName: qa.RandomName("sdk-"), AwsCredentials: provisioning.CreateCredentialAwsCredentials{ StsRole: &provisioning.CreateCredentialStsRole{ - RoleArn: GetEnvOrSkipTest(t, "TEST_LOGDELIVERY_ARN"), + RoleArn: qa.GetEnvOrSkipTest(t, "TEST_LOGDELIVERY_ARN"), }, }, }) @@ -39,9 +40,9 @@ func TestMwsAccLogDelivery(t *testing.T) { defer a.Credentials.DeleteByCredentialsId(ctx, creds.CredentialsId) bucket, err := a.Storage.Create(ctx, provisioning.CreateStorageConfigurationRequest{ - StorageConfigurationName: RandomName("sdk-"), + StorageConfigurationName: qa.RandomName("sdk-"), RootBucketInfo: provisioning.RootBucketInfo{ - BucketName: RandomName("sdk-bucket-"), + BucketName: qa.RandomName("sdk-bucket-"), }, }) require.NoError(t, err) @@ -50,7 +51,7 @@ func TestMwsAccLogDelivery(t *testing.T) { // TODO: OpenAPI: x-databricks-sdk-inline on schema created, err := a.LogDelivery.Create(ctx, billing.WrappedCreateLogDeliveryConfiguration{ LogDeliveryConfiguration: &billing.CreateLogDeliveryConfigurationParams{ - ConfigName: RandomName("sdk-go-"), + ConfigName: qa.RandomName("sdk-go-"), CredentialsId: creds.CredentialsId, StorageConfigurationId: bucket.StorageConfigurationId, LogType: billing.LogTypeAuditLogs, @@ -78,7 +79,7 @@ func TestMwsAccLogDelivery(t *testing.T) { } func TestMwsAccBudgets(t *testing.T) { - ctx, a := accountTest(t) + ctx, a := qa.AccountTest(t) if !a.Config.IsAws() { t.SkipNow() } @@ -86,7 +87,7 @@ func TestMwsAccBudgets(t *testing.T) { // TODO: OpenAPI: x-databricks-sdk-inline on schema created, err := a.Budgets.Create(ctx, billing.WrappedBudget{ Budget: billing.Budget{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), Filter: "tag.tagName = 'all'", Period: "1 month", StartDate: "2022-01-01", @@ -105,7 +106,7 @@ func TestMwsAccBudgets(t *testing.T) { err = a.Budgets.Update(ctx, billing.WrappedBudget{ BudgetId: created.Budget.BudgetId, Budget: billing.Budget{ - Name: RandomName("go-sdk-updated-"), + Name: qa.RandomName("go-sdk-updated-"), Filter: "tag.tagName = 'all'", Period: "1 month", StartDate: "2022-01-01", diff --git a/internal/catalog_test.go b/internal/catalog_test.go index 43680795f..eb29ea016 100644 --- a/internal/catalog_test.go +++ b/internal/catalog_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/catalog" "github.com/databricks/databricks-sdk-go/service/sql" "github.com/stretchr/testify/assert" @@ -11,10 +12,10 @@ import ( ) func TestUcAccVolumes(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) createdCatalog, err := w.Catalogs.Create(ctx, catalog.CreateCatalog{ - Name: RandomName("catalog_"), + Name: qa.RandomName("catalog_"), }) require.NoError(t, err) t.Cleanup(func() { @@ -26,7 +27,7 @@ func TestUcAccVolumes(t *testing.T) { }) createdSchema, err := w.Schemas.Create(ctx, catalog.CreateSchema{ - Name: RandomName("schema_"), + Name: qa.RandomName("schema_"), CatalogName: createdCatalog.Name, }) require.NoError(t, err) @@ -36,26 +37,26 @@ func TestUcAccVolumes(t *testing.T) { }) storageCredential, err := w.StorageCredentials.Create(ctx, catalog.CreateStorageCredential{ - Name: RandomName("creds-"), + Name: qa.RandomName("creds-"), AwsIamRole: &catalog.AwsIamRole{ - RoleArn: GetEnvOrSkipTest(t, "TEST_METASTORE_DATA_ACCESS_ARN"), + RoleArn: qa.GetEnvOrSkipTest(t, "TEST_METASTORE_DATA_ACCESS_ARN"), }, Comment: "created via SDK", }) require.NoError(t, err) externalLocation, err := w.ExternalLocations.Create(ctx, catalog.CreateExternalLocation{ - Name: RandomName("location-"), + Name: qa.RandomName("location-"), CredentialName: storageCredential.Name, Comment: "created via SDK", - Url: "s3://" + GetEnvOrSkipTest(t, "TEST_BUCKET") + "/" + RandomName("somepath-"), + Url: "s3://" + qa.GetEnvOrSkipTest(t, "TEST_BUCKET") + "/" + qa.RandomName("somepath-"), }) require.NoError(t, err) createdVolume, err := w.Volumes.Create(ctx, catalog.CreateVolumeRequestContent{ CatalogName: createdCatalog.Name, SchemaName: createdSchema.Name, - Name: RandomName("volume_"), + Name: qa.RandomName("volume_"), StorageLocation: externalLocation.Url, VolumeType: catalog.VolumeTypeExternal, }) @@ -85,10 +86,10 @@ func TestUcAccVolumes(t *testing.T) { } func TestUcAccTables(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) createdCatalog, err := w.Catalogs.Create(ctx, catalog.CreateCatalog{ - Name: RandomName("catalog_"), + Name: qa.RandomName("catalog_"), }) require.NoError(t, err) t.Cleanup(func() { @@ -100,7 +101,7 @@ func TestUcAccTables(t *testing.T) { }) createdSchema, err := w.Schemas.Create(ctx, catalog.CreateSchema{ - Name: RandomName("schema_"), + Name: qa.RandomName("schema_"), CatalogName: createdCatalog.Name, }) require.NoError(t, err) @@ -109,12 +110,12 @@ func TestUcAccTables(t *testing.T) { require.NoError(t, err) }) - tableName := RandomName("foo_") + tableName := qa.RandomName("foo_") tableFullName := fmt.Sprintf("%s.%s.%s", createdCatalog.Name, createdSchema.Name, tableName) // creates tableFullName _, err = w.StatementExecution.ExecuteAndWait(ctx, sql.ExecuteStatementRequest{ - WarehouseId: GetEnvOrSkipTest(t, "TEST_DEFAULT_WAREHOUSE_ID"), + WarehouseId: qa.GetEnvOrSkipTest(t, "TEST_DEFAULT_WAREHOUSE_ID"), Catalog: createdCatalog.Name, Schema: createdSchema.Name, Statement: fmt.Sprintf("CREATE TABLE %s AS SELECT 2+2 as four", tableName), @@ -136,7 +137,7 @@ func TestUcAccTables(t *testing.T) { require.NoError(t, err) assert.Equal(t, createdCatalog.Name, createdTable.CatalogName) - accountLevelGroupName := GetEnvOrSkipTest(t, "TEST_DATA_ENG_GROUP") + accountLevelGroupName := qa.GetEnvOrSkipTest(t, "TEST_DATA_ENG_GROUP") x, err := w.Grants.Update(ctx, catalog.UpdatePermissions{ FullName: createdTable.FullName, SecurableType: catalog.SecurableTypeTable, @@ -166,17 +167,17 @@ func TestUcAccTables(t *testing.T) { } func TestUcAccStorageCredentialsOnAws(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) if !w.Config.IsAws() { - skipf(t)("not not aws") + t.Skip("not on aws") } // TODO: OpenAPI: retry protocol on late validation for storage // See https://github.com/databricks/terraform-provider-databricks/issues/1424 created, err := w.StorageCredentials.Create(ctx, catalog.CreateStorageCredential{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), AwsIamRole: &catalog.AwsIamRole{ - RoleArn: GetEnvOrSkipTest(t, "TEST_METASTORE_DATA_ACCESS_ARN"), + RoleArn: qa.GetEnvOrSkipTest(t, "TEST_METASTORE_DATA_ACCESS_ARN"), }, }) require.NoError(t, err) @@ -187,9 +188,9 @@ func TestUcAccStorageCredentialsOnAws(t *testing.T) { _, err = w.StorageCredentials.Update(ctx, catalog.UpdateStorageCredential{ Name: created.Name, - Comment: RandomName("comment "), + Comment: qa.RandomName("comment "), AwsIamRole: &catalog.AwsIamRole{ - RoleArn: GetEnvOrSkipTest(t, "TEST_METASTORE_DATA_ACCESS_ARN"), + RoleArn: qa.GetEnvOrSkipTest(t, "TEST_METASTORE_DATA_ACCESS_ARN"), }, }) require.NoError(t, err) @@ -204,15 +205,15 @@ func TestUcAccStorageCredentialsOnAws(t *testing.T) { } func TestUcAccExternalLocationsOnAws(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) if !w.Config.IsAws() { - skipf(t)("not not aws") + t.Skip("not not aws") } credential, err := w.StorageCredentials.Create(ctx, catalog.CreateStorageCredential{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), AwsIamRole: &catalog.AwsIamRole{ - RoleArn: GetEnvOrSkipTest(t, "TEST_METASTORE_DATA_ACCESS_ARN"), + RoleArn: qa.GetEnvOrSkipTest(t, "TEST_METASTORE_DATA_ACCESS_ARN"), }, }) require.NoError(t, err) @@ -222,9 +223,9 @@ func TestUcAccExternalLocationsOnAws(t *testing.T) { }) created, err := w.ExternalLocations.Create(ctx, catalog.CreateExternalLocation{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), CredentialName: credential.Name, - Url: fmt.Sprintf("s3://%s/%s", GetEnvOrSkipTest(t, "TEST_BUCKET"), RandomName("l-")), + Url: fmt.Sprintf("s3://%s/%s", qa.GetEnvOrSkipTest(t, "TEST_BUCKET"), qa.RandomName("l-")), }) require.NoError(t, err) t.Cleanup(func() { @@ -235,7 +236,7 @@ func TestUcAccExternalLocationsOnAws(t *testing.T) { _, err = w.ExternalLocations.Update(ctx, catalog.UpdateExternalLocation{ Name: created.Name, CredentialName: credential.Name, - Url: fmt.Sprintf("s3://%s/%s", GetEnvOrSkipTest(t, "TEST_BUCKET"), RandomName("l-")), + Url: fmt.Sprintf("s3://%s/%s", qa.GetEnvOrSkipTest(t, "TEST_BUCKET"), qa.RandomName("l-")), }) require.NoError(t, err) @@ -248,10 +249,10 @@ func TestUcAccExternalLocationsOnAws(t *testing.T) { } func TestUcAccMetastores(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) created, err := w.Metastores.Create(ctx, catalog.CreateMetastore{ - Name: RandomName("go-sdk-"), - StorageRoot: fmt.Sprintf("s3://%s/%s", GetEnvOrSkipTest(t, "TEST_BUCKET"), RandomName("t=")), + Name: qa.RandomName("go-sdk-"), + StorageRoot: fmt.Sprintf("s3://%s/%s", qa.GetEnvOrSkipTest(t, "TEST_BUCKET"), qa.RandomName("t=")), }) require.NoError(t, err) t.Cleanup(func() { @@ -275,14 +276,14 @@ func TestUcAccMetastores(t *testing.T) { _, err = w.Metastores.Update(ctx, catalog.UpdateMetastore{ Id: created.MetastoreId, - Name: RandomName("go-sdk-updated"), + Name: qa.RandomName("go-sdk-updated"), }) require.NoError(t, err) _, err = w.Metastores.GetById(ctx, created.MetastoreId) require.NoError(t, err) - workspaceId := MustParseInt64(GetEnvOrSkipTest(t, "TEST_WORKSPACE_ID")) + workspaceId := qa.MustParseInt64(qa.GetEnvOrSkipTest(t, "TEST_WORKSPACE_ID")) err = w.Metastores.Assign(ctx, catalog.CreateMetastoreAssignment{ MetastoreId: created.MetastoreId, @@ -308,10 +309,10 @@ func TestUcAccMetastores(t *testing.T) { } func TestUcAccCatalogs(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) created, err := w.Catalogs.Create(ctx, catalog.CreateCatalog{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { @@ -337,10 +338,10 @@ func TestUcAccCatalogs(t *testing.T) { } func TestUcAccCatalogWorkspaceBindings(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) created, err := w.Catalogs.Create(ctx, catalog.CreateCatalog{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { @@ -357,7 +358,7 @@ func TestUcAccCatalogWorkspaceBindings(t *testing.T) { }) require.NoError(t, err) - thisWorkspaceID := MustParseInt64(GetEnvOrSkipTest(t, "THIS_WORKSPACE_ID")) + thisWorkspaceID := qa.MustParseInt64(qa.GetEnvOrSkipTest(t, "THIS_WORKSPACE_ID")) _, err = w.WorkspaceBindings.Update(ctx, catalog.UpdateWorkspaceBindings{ Name: created.Name, AssignWorkspaces: []int64{thisWorkspaceID}, @@ -371,10 +372,10 @@ func TestUcAccCatalogWorkspaceBindings(t *testing.T) { } func TestUcAccSchemas(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) newCatalog, err := w.Catalogs.Create(ctx, catalog.CreateCatalog{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { @@ -386,7 +387,7 @@ func TestUcAccSchemas(t *testing.T) { }) created, err := w.Schemas.Create(ctx, catalog.CreateSchema{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), CatalogName: newCatalog.Name, }) require.NoError(t, err) @@ -397,7 +398,7 @@ func TestUcAccSchemas(t *testing.T) { }) _, err = w.Schemas.Update(ctx, catalog.UpdateSchema{ FullName: created.FullName, - Comment: RandomName("comment "), + Comment: qa.RandomName("comment "), }) require.NoError(t, err) diff --git a/internal/clusterpolicies_test.go b/internal/clusterpolicies_test.go index ca7e8fa71..95e3639eb 100644 --- a/internal/clusterpolicies_test.go +++ b/internal/clusterpolicies_test.go @@ -3,13 +3,14 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccClusterPolicyFamilies(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) all, err := w.PolicyFamilies.ListAll(ctx, compute.ListPolicyFamiliesRequest{}) require.NoError(t, err) @@ -22,10 +23,10 @@ func TestAccClusterPolicyFamilies(t *testing.T) { } func TestAccClusterPolicies(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) created, err := w.ClusterPolicies.Create(ctx, compute.CreatePolicy{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), Definition: `{ "spark_conf.spark.databricks.delta.preview.enabled": { "type": "fixed", diff --git a/internal/clusters_test.go b/internal/clusters_test.go index 5b882785f..bbee755ab 100644 --- a/internal/clusters_test.go +++ b/internal/clusters_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/databricks/databricks-sdk-go" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/retries" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/databricks/databricks-sdk-go/service/iam" @@ -16,14 +17,14 @@ import ( func sharedRunningCluster(t *testing.T, ctx context.Context, w *databricks.WorkspaceClient) string { - clusterId := GetEnvOrSkipTest(t, "TEST_GO_SDK_CLUSTER_ID") + clusterId := qa.GetEnvOrSkipTest(t, "TEST_GO_SDK_CLUSTER_ID") err := w.Clusters.EnsureClusterIsRunning(ctx, clusterId) require.NoError(t, err) return clusterId } func TestAccClustersCreateFailsWithTimeoutNoTranspile(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) // Fetch list of spark runtime versions sparkVersions, err := w.Clusters.SparkVersions(ctx) @@ -39,9 +40,9 @@ func TestAccClustersCreateFailsWithTimeoutNoTranspile(t *testing.T) { // Create a cluster with unreasonably low timeout _, err = w.Clusters.CreateAndWait(ctx, compute.CreateCluster{ - ClusterName: RandomName(t.Name()), + ClusterName: qa.RandomName(t.Name()), SparkVersion: latest, - InstancePoolId: GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), + InstancePoolId: qa.GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), AutoterminationMinutes: 10, NumWorkers: 1, }, retries.Timeout[compute.ClusterInfo](15*time.Second), @@ -57,7 +58,7 @@ func TestAccClustersCreateFailsWithTimeoutNoTranspile(t *testing.T) { } func TestAccAwsInstanceProfiles(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) if !w.Config.IsAws() { t.Skipf("runs only on AWS") } @@ -84,9 +85,9 @@ func TestAccAwsInstanceProfiles(t *testing.T) { } func TestAccClustersApiIntegration(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) - clusterName := RandomName("sdk-go-cluster-") + clusterName := qa.RandomName("sdk-go-cluster-") // Select the latest LTS version latest, err := w.Clusters.SelectSparkVersion(ctx, compute.SparkVersionRequest{ @@ -98,7 +99,7 @@ func TestAccClustersApiIntegration(t *testing.T) { clstr, err := w.Clusters.CreateAndWait(ctx, compute.CreateCluster{ ClusterName: clusterName, SparkVersion: latest, - InstancePoolId: GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), + InstancePoolId: qa.GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), AutoterminationMinutes: 15, NumWorkers: 1, }) @@ -128,7 +129,7 @@ func TestAccClustersApiIntegration(t *testing.T) { ClusterId: clstr.ClusterId, SparkVersion: latest, ClusterName: clusterName, - InstancePoolId: GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), + InstancePoolId: qa.GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), // change auto-termination and number of workers AutoterminationMinutes: 10, @@ -197,7 +198,7 @@ func TestAccClustersApiIntegration(t *testing.T) { assert.Equal(t, clusterInfo.ClusterName, clusterName) otherOwner, err := w.Users.Create(ctx, iam.User{ - UserName: RandomEmail(), + UserName: qa.RandomEmail(), }) require.NoError(t, err) defer w.Users.DeleteById(ctx, otherOwner.Id) diff --git a/internal/commands_test.go b/internal/commands_test.go index 005c47860..c8e744040 100644 --- a/internal/commands_test.go +++ b/internal/commands_test.go @@ -3,15 +3,16 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccCommands(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) - clusterId := GetEnvOrSkipTest(t, "TEST_DEFAULT_CLUSTER_ID") + clusterId := qa.GetEnvOrSkipTest(t, "TEST_DEFAULT_CLUSTER_ID") commandContext, err := w.CommandExecution.Start(ctx, clusterId, compute.LanguagePython) require.NoError(t, err) @@ -32,9 +33,9 @@ func TestAccCommands(t *testing.T) { } func TestAccCommandsDirectUsage(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) - clusterId := GetEnvOrSkipTest(t, "TEST_DEFAULT_CLUSTER_ID") + clusterId := qa.GetEnvOrSkipTest(t, "TEST_DEFAULT_CLUSTER_ID") err := w.Clusters.EnsureClusterIsRunning(ctx, clusterId) require.NoError(t, err) diff --git a/internal/dbsql_test.go b/internal/dbsql_test.go index 30c6354a0..bc9c929a3 100644 --- a/internal/dbsql_test.go +++ b/internal/dbsql_test.go @@ -3,13 +3,14 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/sql" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccQueries(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) srcs, err := w.DataSources.List(ctx) require.NoError(t, err) @@ -18,7 +19,7 @@ func TestAccQueries(t *testing.T) { } query, err := w.Queries.Create(ctx, sql.QueryPostContent{ - Name: RandomName("go-sdk/test/"), + Name: qa.RandomName("go-sdk/test/"), DataSourceId: srcs[0].Id, Description: "test query from Go SDK", Query: "SHOW TABLES", @@ -39,7 +40,7 @@ func TestAccQueries(t *testing.T) { updated, err := w.Queries.Update(ctx, sql.QueryEditContent{ QueryId: query.Id, - Name: RandomName("go-sdk-updated"), + Name: qa.RandomName("go-sdk-updated"), DataSourceId: srcs[0].Id, Description: "UPDATED: test query from Go SDK", Query: "SELECT 2+2", @@ -49,7 +50,7 @@ func TestAccQueries(t *testing.T) { } func TestAccAlerts(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) srcs, err := w.DataSources.List(ctx) require.NoError(t, err) @@ -58,7 +59,7 @@ func TestAccAlerts(t *testing.T) { } query, err := w.Queries.Create(ctx, sql.QueryPostContent{ - Name: RandomName("go-sdk/test/"), + Name: qa.RandomName("go-sdk/test/"), DataSourceId: srcs[0].Id, Description: "test query from Go SDK", Query: "SELECT 1", @@ -72,7 +73,7 @@ func TestAccAlerts(t *testing.T) { Op: "==", Value: "1", }, - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), QueryId: query.Id, }) require.NoError(t, err) @@ -85,7 +86,7 @@ func TestAccAlerts(t *testing.T) { Value: "1", }, AlertId: alert.Id, - Name: RandomName("go-sdk-updated-"), + Name: qa.RandomName("go-sdk-updated-"), QueryId: query.Id, }) require.NoError(t, err) @@ -107,10 +108,10 @@ func TestAccAlerts(t *testing.T) { } func TestAccDashboards(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) created, err := w.Dashboards.Create(ctx, sql.CreateDashboardRequest{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), }) require.NoError(t, err) diff --git a/internal/deployment_test.go b/internal/deployment_test.go index 4f68109e5..d4f167665 100644 --- a/internal/deployment_test.go +++ b/internal/deployment_test.go @@ -3,21 +3,22 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/provisioning" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestMwsAccStorage(t *testing.T) { - ctx, a := accountTest(t) + ctx, a := qa.AccountTest(t) if !a.Config.IsAws() { t.SkipNow() } storage, err := a.Storage.Create(ctx, provisioning.CreateStorageConfigurationRequest{ - StorageConfigurationName: RandomName("sdk-"), + StorageConfigurationName: qa.RandomName("sdk-"), RootBucketInfo: provisioning.RootBucketInfo{ - BucketName: RandomName("sdk-bucket-"), + BucketName: qa.RandomName("sdk-bucket-"), }, }) require.NoError(t, err) @@ -40,15 +41,15 @@ func TestMwsAccStorage(t *testing.T) { } func TestMwsAccNetworks(t *testing.T) { - ctx, a := accountTest(t) + ctx, a := qa.AccountTest(t) if !a.Config.IsAws() { t.SkipNow() } netw, err := a.Networks.Create(ctx, provisioning.CreateNetworkRequest{ - NetworkName: RandomName("sdk-"), - VpcId: RandomHex("vpc-", 17), - SubnetIds: []string{RandomHex("subnet-", 17), RandomHex("subnet-", 17)}, - SecurityGroupIds: []string{RandomHex("sg-", 17)}, + NetworkName: qa.RandomName("sdk-"), + VpcId: qa.RandomHex("vpc-", 17), + SubnetIds: []string{qa.RandomHex("subnet-", 17), qa.RandomHex("subnet-", 17)}, + SecurityGroupIds: []string{qa.RandomHex("sg-", 17)}, }) require.NoError(t, err) defer func() { @@ -69,15 +70,15 @@ func TestMwsAccNetworks(t *testing.T) { } func TestMwsAccCredentials(t *testing.T) { - ctx, a := accountTest(t) + ctx, a := qa.AccountTest(t) if !a.Config.IsAws() { t.SkipNow() } role, err := a.Credentials.Create(ctx, provisioning.CreateCredentialRequest{ - CredentialsName: RandomName("sdk-"), + CredentialsName: qa.RandomName("sdk-"), AwsCredentials: provisioning.CreateCredentialAwsCredentials{ StsRole: &provisioning.CreateCredentialStsRole{ - RoleArn: GetEnvOrSkipTest(t, "TEST_CROSSACCOUNT_ARN"), + RoleArn: qa.GetEnvOrSkipTest(t, "TEST_CROSSACCOUNT_ARN"), }, }, }) @@ -101,15 +102,15 @@ func TestMwsAccCredentials(t *testing.T) { } func TestMwsAccEncryptionKeys(t *testing.T) { - ctx, a := accountTest(t) + ctx, a := qa.AccountTest(t) if !a.Config.IsAws() { t.SkipNow() } created, err := a.EncryptionKeys.Create(ctx, provisioning.CreateCustomerManagedKeyRequest{ AwsKeyInfo: &provisioning.CreateAwsKeyInfo{ - KeyArn: GetEnvOrSkipTest(t, "TEST_MANAGED_KMS_KEY_ARN"), - KeyAlias: GetEnvOrSkipTest(t, "TEST_STORAGE_KMS_KEY_ALIAS"), + KeyArn: qa.GetEnvOrSkipTest(t, "TEST_MANAGED_KMS_KEY_ARN"), + KeyAlias: qa.GetEnvOrSkipTest(t, "TEST_STORAGE_KMS_KEY_ALIAS"), }, UseCases: []provisioning.KeyUseCase{provisioning.KeyUseCaseManagedServices}, }) @@ -130,14 +131,14 @@ func TestMwsAccEncryptionKeys(t *testing.T) { } func TestMwsAccPrivateAccess(t *testing.T) { - ctx, a := accountTest(t) + ctx, a := qa.AccountTest(t) if !a.Config.IsAws() { t.SkipNow() } created, err := a.PrivateAccess.Create(ctx, provisioning.UpsertPrivateAccessSettingsRequest{ - PrivateAccessSettingsName: RandomName("go-sdk-"), - Region: GetEnvOrSkipTest(t, "AWS_REGION"), + PrivateAccessSettingsName: qa.RandomName("go-sdk-"), + Region: qa.GetEnvOrSkipTest(t, "AWS_REGION"), }) require.NoError(t, err) @@ -147,8 +148,8 @@ func TestMwsAccPrivateAccess(t *testing.T) { }) err = a.PrivateAccess.Replace(ctx, provisioning.UpsertPrivateAccessSettingsRequest{ PrivateAccessSettingsId: created.PrivateAccessSettingsId, - PrivateAccessSettingsName: RandomName("go-sdk-"), - Region: GetEnvOrSkipTest(t, "AWS_REGION"), + PrivateAccessSettingsName: qa.RandomName("go-sdk-"), + Region: qa.GetEnvOrSkipTest(t, "AWS_REGION"), }) require.NoError(t, err) @@ -169,15 +170,15 @@ func TestMwsAccPrivateAccess(t *testing.T) { } func TestMwsAccVpcEndpoints(t *testing.T) { - ctx, a := accountTest(t) + ctx, a := qa.AccountTest(t) if !a.Config.IsAws() { t.SkipNow() } created, err := a.VpcEndpoints.Create(ctx, provisioning.CreateVpcEndpointRequest{ - AwsVpcEndpointId: GetEnvOrSkipTest(t, "TEST_RELAY_VPC_ENDPOINT"), - Region: GetEnvOrSkipTest(t, "AWS_REGION"), - VpcEndpointName: RandomName("go-sdk-"), + AwsVpcEndpointId: qa.GetEnvOrSkipTest(t, "TEST_RELAY_VPC_ENDPOINT"), + Region: qa.GetEnvOrSkipTest(t, "AWS_REGION"), + VpcEndpointName: qa.RandomName("go-sdk-"), }) require.NoError(t, err) @@ -196,15 +197,15 @@ func TestMwsAccVpcEndpoints(t *testing.T) { } func TestMwsAccWorkspaces(t *testing.T) { - ctx, a := accountTest(t) + ctx, a := qa.AccountTest(t) if !a.Config.IsAws() { t.SkipNow() } storage, err := a.Storage.Create(ctx, provisioning.CreateStorageConfigurationRequest{ - StorageConfigurationName: RandomName("go-sdk-"), + StorageConfigurationName: qa.RandomName("go-sdk-"), RootBucketInfo: provisioning.RootBucketInfo{ - BucketName: GetEnvOrSkipTest(t, "TEST_ROOT_BUCKET"), + BucketName: qa.GetEnvOrSkipTest(t, "TEST_ROOT_BUCKET"), }, }) require.NoError(t, err) @@ -216,10 +217,10 @@ func TestMwsAccWorkspaces(t *testing.T) { // TODO: OpenAPI: Document retry protocol on AWS IAM registration errors // See https://github.com/databricks/terraform-provider-databricks/issues/1424 role, err := a.Credentials.Create(ctx, provisioning.CreateCredentialRequest{ - CredentialsName: RandomName("go-sdk-"), + CredentialsName: qa.RandomName("go-sdk-"), AwsCredentials: provisioning.CreateCredentialAwsCredentials{ StsRole: &provisioning.CreateCredentialStsRole{ - RoleArn: GetEnvOrSkipTest(t, "TEST_CROSSACCOUNT_ARN"), + RoleArn: qa.GetEnvOrSkipTest(t, "TEST_CROSSACCOUNT_ARN"), }, }, }) @@ -231,8 +232,8 @@ func TestMwsAccWorkspaces(t *testing.T) { // TODO: Add DNS reachability utility created, err := a.Workspaces.CreateAndWait(ctx, provisioning.CreateWorkspaceRequest{ - WorkspaceName: RandomName("go-sdk-"), - AwsRegion: GetEnvOrSkipTest(t, "AWS_REGION"), + WorkspaceName: qa.RandomName("go-sdk-"), + AwsRegion: qa.GetEnvOrSkipTest(t, "AWS_REGION"), CredentialsId: role.CredentialsId, StorageConfigurationId: storage.StorageConfigurationId, }) @@ -243,10 +244,10 @@ func TestMwsAccWorkspaces(t *testing.T) { }) updateRole, err := a.Credentials.Create(ctx, provisioning.CreateCredentialRequest{ - CredentialsName: RandomName("go-sdk-"), + CredentialsName: qa.RandomName("go-sdk-"), AwsCredentials: provisioning.CreateCredentialAwsCredentials{ StsRole: &provisioning.CreateCredentialStsRole{ - RoleArn: GetEnvOrSkipTest(t, "TEST_CROSSACCOUNT_ARN"), + RoleArn: qa.GetEnvOrSkipTest(t, "TEST_CROSSACCOUNT_ARN"), }, }, }) diff --git a/internal/files_test.go b/internal/files_test.go index ca7c8b10e..847e815ac 100644 --- a/internal/files_test.go +++ b/internal/files_test.go @@ -12,6 +12,7 @@ import ( "testing" "time" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/files" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -27,9 +28,9 @@ func (buf hashable) Hash() uint32 { func TestAccFilesAPI(t *testing.T) { t.SkipNow() // until available on prod - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) - filePath := RandomName("/Volumes/bogdanghita/default/v3_shared/sdk-testing/txt-") + filePath := qa.RandomName("/Volumes/bogdanghita/default/v3_shared/sdk-testing/txt-") err := w.Files.Upload(ctx, filePath, strings.NewReader("abcd")) require.NoError(t, err) t.Cleanup(func() { @@ -42,12 +43,12 @@ func TestAccFilesAPI(t *testing.T) { } func TestAccDbfsOpen(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) if w.Config.IsGcp() { t.Skip("dbfs not available on gcp") } - path := RandomName("/tmp/.sdk/fake") + path := qa.RandomName("/tmp/.sdk/fake") rand.Seed(time.Now().UnixNano()) in := make([]byte, 1.44*1e6) _, _ = rand.Read(in) @@ -120,12 +121,12 @@ func TestAccDbfsOpen(t *testing.T) { } func TestAccDbfsOpenDirectory(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) if w.Config.IsGcp() { t.Skip("dbfs not available on gcp") } - path := RandomName("/tmp/.sdk/fake") + path := qa.RandomName("/tmp/.sdk/fake") defer w.Dbfs.Delete(ctx, files.Delete{ Path: path, @@ -149,12 +150,12 @@ func TestAccDbfsOpenDirectory(t *testing.T) { } func TestAccDbfsReadFileWriteFile(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) if w.Config.IsGcp() { t.Skip("dbfs not available on gcp") } - path := RandomName("/tmp/.sdk/fake") + path := qa.RandomName("/tmp/.sdk/fake") rand.Seed(time.Now().UnixNano()) in := make([]byte, 1.44*1e6) _, _ = rand.Read(in) @@ -185,15 +186,15 @@ func TestAccDbfsReadFileWriteFile(t *testing.T) { } func TestAccListDbfsIntegration(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) if w.Config.IsGcp() { t.Skip("dbfs not available on gcp") } - testFile1 := RandomName("f001-") - testFile2 := RandomName("f002-") - testPath1 := RandomName("/tmp/.sdk/001-") - testPath2 := RandomName("/tmp/.sdk/002-") + testFile1 := qa.RandomName("f001-") + testFile2 := qa.RandomName("f002-") + testPath1 := qa.RandomName("/tmp/.sdk/001-") + testPath2 := qa.RandomName("/tmp/.sdk/002-") t.Cleanup(func() { // recursively delete the test dir1 and any test files inside it diff --git a/internal/git_credentials_test.go b/internal/git_credentials_test.go index cab97a6df..65d77b76c 100644 --- a/internal/git_credentials_test.go +++ b/internal/git_credentials_test.go @@ -3,13 +3,14 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/workspace" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccGitCredentials(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) list, err := w.GitCredentials.ListAll(ctx) require.NoError(t, err) @@ -32,8 +33,8 @@ func TestAccGitCredentials(t *testing.T) { err = w.GitCredentials.Update(ctx, workspace.UpdateCredentials{ CredentialId: cr.CredentialId, GitProvider: "gitHub", - GitUsername: RandomEmail(), - PersonalAccessToken: RandomName(), + GitUsername: qa.RandomEmail(), + PersonalAccessToken: qa.RandomName(), }) require.NoError(t, err) diff --git a/internal/globalinitscripts_test.go b/internal/globalinitscripts_test.go index bd831db42..36043c4e3 100644 --- a/internal/globalinitscripts_test.go +++ b/internal/globalinitscripts_test.go @@ -4,16 +4,17 @@ import ( "encoding/base64" "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccGlobalInitScripts(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) created, err := w.GlobalInitScripts.Create(ctx, compute.GlobalInitScriptCreateRequest{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), Script: base64.StdEncoding.EncodeToString([]byte("echo 1")), Enabled: true, Position: 10, @@ -24,7 +25,7 @@ func TestAccGlobalInitScripts(t *testing.T) { err = w.GlobalInitScripts.Update(ctx, compute.GlobalInitScriptUpdateRequest{ ScriptId: created.ScriptId, - Name: RandomName("go-sdk-updated-"), + Name: qa.RandomName("go-sdk-updated-"), Script: base64.StdEncoding.EncodeToString([]byte("echo 2")), }) require.NoError(t, err) diff --git a/internal/instancepools_test.go b/internal/instancepools_test.go index d3621b411..8b87247c4 100644 --- a/internal/instancepools_test.go +++ b/internal/instancepools_test.go @@ -3,13 +3,14 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccInstancePools(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) smallest, err := w.Clusters.SelectNodeType(ctx, compute.NodeTypeRequest{ LocalDisk: true, @@ -17,7 +18,7 @@ func TestAccInstancePools(t *testing.T) { require.NoError(t, err) created, err := w.InstancePools.Create(ctx, compute.CreateInstancePool{ - InstancePoolName: RandomName("go-sdk-"), + InstancePoolName: qa.RandomName("go-sdk-"), NodeTypeId: smallest, }) require.NoError(t, err) @@ -26,7 +27,7 @@ func TestAccInstancePools(t *testing.T) { err = w.InstancePools.Edit(ctx, compute.EditInstancePool{ InstancePoolId: created.InstancePoolId, - InstancePoolName: RandomName("go-sdk-updated"), + InstancePoolName: qa.RandomName("go-sdk-updated"), NodeTypeId: smallest, }) require.NoError(t, err) diff --git a/internal/ipaccesslists_test.go b/internal/ipaccesslists_test.go index ab6d5f17c..0a38bbe38 100644 --- a/internal/ipaccesslists_test.go +++ b/internal/ipaccesslists_test.go @@ -3,16 +3,17 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/settings" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccIpAccessLists(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) created, err := w.IpAccessLists.Create(ctx, settings.CreateIpAccessList{ - Label: RandomName("go-sdk-"), + Label: qa.RandomName("go-sdk-"), IpAddresses: []string{"1.0.0.0/16"}, ListType: settings.ListTypeBlock, }) @@ -22,7 +23,7 @@ func TestAccIpAccessLists(t *testing.T) { err = w.IpAccessLists.Replace(ctx, settings.ReplaceIpAccessList{ IpAccessListId: created.IpAccessList.ListId, - Label: RandomName("go-sdk-updated-"), + Label: qa.RandomName("go-sdk-updated-"), IpAddresses: []string{"1.0.0.0/24"}, ListType: settings.ListTypeBlock, Enabled: false, diff --git a/internal/jobs_test.go b/internal/jobs_test.go index cfba83ddc..e1f4d27a8 100644 --- a/internal/jobs_test.go +++ b/internal/jobs_test.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/databricks/databricks-sdk-go/service/workspace" @@ -12,7 +13,7 @@ import ( ) func TestAccJobsApiFullIntegration(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) clusterId := sharedRunningCluster(t, ctx, w) notebookPath := myNotebookPath(t, w) @@ -29,13 +30,13 @@ func TestAccJobsApiFullIntegration(t *testing.T) { require.NoError(t, err) run, err := w.Jobs.SubmitAndWait(ctx, jobs.SubmitRun{ - RunName: RandomName("go-sdk-SubmitAndWait-"), + RunName: qa.RandomName("go-sdk-SubmitAndWait-"), Tasks: []jobs.RunSubmitTaskSettings{{ ExistingClusterId: clusterId, NotebookTask: &jobs.NotebookTask{ NotebookPath: notebookPath, }, - TaskKey: RandomName(), + TaskKey: qa.RandomName(), }}, }) require.NoError(t, err) @@ -46,7 +47,7 @@ func TestAccJobsApiFullIntegration(t *testing.T) { assert.Equal(t, output.NotebookOutput.Result, "hello") createdJob, err := w.Jobs.Create(ctx, jobs.CreateJob{ - Name: RandomName("go-sdk-Create-"), + Name: qa.RandomName("go-sdk-Create-"), Tasks: []jobs.JobTaskSettings{{ Description: "test", ExistingClusterId: clusterId, @@ -100,7 +101,7 @@ func TestAccJobsApiFullIntegration(t *testing.T) { require.NoError(t, err) assert.GreaterOrEqual(t, len(repairedRun.Tasks), 1) - newName := RandomName("updated") + newName := qa.RandomName("updated") err = w.Jobs.Update(ctx, jobs.UpdateJob{ JobId: createdJob.JobId, NewSettings: &jobs.JobSettings{ @@ -116,7 +117,7 @@ func TestAccJobsApiFullIntegration(t *testing.T) { assert.Equal(t, byId.Settings.Name, newName) assert.Equal(t, byId.Settings.MaxConcurrentRuns, 5) - newName = RandomName("updated-for-reset") + newName = qa.RandomName("updated-for-reset") err = w.Jobs.Reset(ctx, jobs.ResetJob{ JobId: byId.JobId, NewSettings: jobs.JobSettings{ @@ -142,7 +143,7 @@ func TestAccJobsApiFullIntegration(t *testing.T) { } func TestAccJobsListAllNoDuplicatesNoTranspile(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) // Fetch list of spark runtime versions sparkVersions, err := w.Clusters.SparkVersions(ctx) @@ -162,7 +163,7 @@ func TestAccJobsListAllNoDuplicatesNoTranspile(t *testing.T) { for i := 0; i < 34; i++ { createdJob, err := w.Jobs.Create(ctx, jobs.CreateJob{ - Name: RandomName(t.Name()), + Name: qa.RandomName(t.Name()), Tasks: []jobs.JobTaskSettings{{ Description: "test", NewCluster: &compute.BaseClusterInfo{ @@ -193,7 +194,7 @@ func TestAccJobsListAllNoDuplicatesNoTranspile(t *testing.T) { } func TestAccJobsListWithLimitNoTranspile(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) sparkVersions, err := w.Clusters.SparkVersions(ctx) require.NoError(t, err) @@ -212,7 +213,7 @@ func TestAccJobsListWithLimitNoTranspile(t *testing.T) { for i := 0; i < 11; i++ { createdJob, err := w.Jobs.Create(ctx, jobs.CreateJob{ - Name: RandomName(t.Name()), + Name: qa.RandomName(t.Name()), Tasks: []jobs.JobTaskSettings{{ Description: "test", NewCluster: &compute.BaseClusterInfo{ diff --git a/internal/libraries_test.go b/internal/libraries_test.go index 914867efe..20ebe1cfa 100644 --- a/internal/libraries_test.go +++ b/internal/libraries_test.go @@ -3,12 +3,13 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/compute" "github.com/stretchr/testify/require" ) func TestAccLibraries(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) clusterId := sharedRunningCluster(t, ctx, w) err := w.Libraries.UpdateAndWait(ctx, compute.Update{ diff --git a/internal/mlflow_test.go b/internal/mlflow_test.go index e76813689..b02e208a5 100644 --- a/internal/mlflow_test.go +++ b/internal/mlflow_test.go @@ -6,16 +6,17 @@ import ( "time" "github.com/databricks/databricks-sdk-go" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/ml" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccExperiments(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) experiment, err := w.Experiments.CreateExperiment(ctx, ml.CreateExperiment{ - Name: RandomName("/tmp/go-sdk-"), + Name: qa.RandomName("/tmp/go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { @@ -26,7 +27,7 @@ func TestAccExperiments(t *testing.T) { }) err = w.Experiments.UpdateExperiment(ctx, ml.UpdateExperiment{ - NewName: RandomName("/tmp/go-sdk-"), + NewName: qa.RandomName("/tmp/go-sdk-"), ExperimentId: experiment.ExperimentId, }) require.NoError(t, err) @@ -42,10 +43,10 @@ func TestAccExperiments(t *testing.T) { } func TestAccMLflowRuns(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) experiment, err := w.Experiments.CreateExperiment(ctx, ml.CreateExperiment{ - Name: RandomName("/tmp/go-sdk-"), + Name: qa.RandomName("/tmp/go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { @@ -81,10 +82,10 @@ func TestAccMLflowRuns(t *testing.T) { } func TestAccModels(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) created, err := w.ModelRegistry.CreateModel(ctx, ml.CreateModelRequest{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { @@ -98,7 +99,7 @@ func TestAccModels(t *testing.T) { err = w.ModelRegistry.UpdateModel(ctx, ml.UpdateModelRequest{ Name: model.RegisteredModelDatabricks.Name, - Description: RandomName("comment "), + Description: qa.RandomName("comment "), }) require.NoError(t, err) @@ -115,9 +116,9 @@ func deleteModel(t *testing.T, w *databricks.WorkspaceClient, ctx context.Contex } func TestAccRegistryWebhooks(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) created, err := w.ModelRegistry.CreateWebhook(ctx, ml.CreateRegistryWebhook{ - Description: RandomName("comment "), + Description: qa.RandomName("comment "), Events: []ml.RegistryWebhookEvent{ml.RegistryWebhookEventModelVersionCreated}, HttpUrlSpec: &ml.HttpUrlSpec{ Url: w.Config.CanonicalHostName(), @@ -133,7 +134,7 @@ func TestAccRegistryWebhooks(t *testing.T) { }) err = w.ModelRegistry.UpdateWebhook(ctx, ml.UpdateRegistryWebhook{ Id: created.Webhook.Id, - Description: RandomName("updated "), + Description: qa.RandomName("updated "), }) require.NoError(t, err) @@ -173,10 +174,10 @@ func deleteModelVersion(t *testing.T, w *databricks.WorkspaceClient, ctx context } func TestAccModelVersions(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) model, err := w.ModelRegistry.CreateModel(ctx, ml.CreateModelRequest{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { @@ -194,7 +195,7 @@ func TestAccModelVersions(t *testing.T) { }) err = w.ModelRegistry.UpdateModelVersion(ctx, ml.UpdateModelVersionRequest{ - Description: RandomName("description "), + Description: qa.RandomName("description "), Name: created.ModelVersion.Name, Version: created.ModelVersion.Version, }) @@ -202,10 +203,10 @@ func TestAccModelVersions(t *testing.T) { } func TestAccModelVersionComments(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) model, err := w.ModelRegistry.CreateModel(ctx, ml.CreateModelRequest{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { @@ -223,7 +224,7 @@ func TestAccModelVersionComments(t *testing.T) { }) created, err := w.ModelRegistry.CreateComment(ctx, ml.CreateComment{ - Comment: RandomName("comment "), + Comment: qa.RandomName("comment "), Name: mv.ModelVersion.Name, Version: mv.ModelVersion.Version, }) @@ -237,7 +238,7 @@ func TestAccModelVersionComments(t *testing.T) { require.NoError(t, err) }) _, err = w.ModelRegistry.UpdateComment(ctx, ml.UpdateComment{ - Comment: RandomName("updated "), + Comment: qa.RandomName("updated "), Id: created.Comment.Id, }) require.NoError(t, err) diff --git a/internal/permissions_test.go b/internal/permissions_test.go index 5b9cb6cc8..a681d31ef 100644 --- a/internal/permissions_test.go +++ b/internal/permissions_test.go @@ -5,6 +5,7 @@ import ( "fmt" "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/iam" "github.com/databricks/databricks-sdk-go/service/workspace" "github.com/stretchr/testify/assert" @@ -12,7 +13,7 @@ import ( ) func TestAccGenericPermissions(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) notebookPath := myNotebookPath(t, w) err := w.Workspace.Import(ctx, workspace.Import{ @@ -35,7 +36,7 @@ func TestAccGenericPermissions(t *testing.T) { assert.True(t, len(levels.PermissionLevels) > 1) group, err := w.Groups.Create(ctx, iam.Group{ - DisplayName: RandomName("go-sdk-"), + DisplayName: qa.RandomName("go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { @@ -63,14 +64,14 @@ func TestAccGenericPermissions(t *testing.T) { } func TestUcAccWorkspaceAssignmentOnAws(t *testing.T) { - ctx, a := ucacctTest(t) + ctx, a := qa.UcacctTest(t) if !a.Config.IsAws() { t.SkipNow() } - workspaceId := MustParseInt64(GetEnvOrSkipTest(t, "TEST_WORKSPACE_ID")) + workspaceId := qa.MustParseInt64(qa.GetEnvOrSkipTest(t, "TEST_WORKSPACE_ID")) spn, err := a.ServicePrincipals.Create(ctx, iam.ServicePrincipal{ - DisplayName: RandomName("sdk-go-"), + DisplayName: qa.RandomName("sdk-go-"), }) require.NoError(t, err) defer func() { @@ -78,7 +79,7 @@ func TestUcAccWorkspaceAssignmentOnAws(t *testing.T) { require.NoError(t, err) }() - spnId := MustParseInt64(spn.Id) + spnId := qa.MustParseInt64(spn.Id) err = a.WorkspaceAssignment.Update(ctx, iam.UpdateWorkspaceAssignments{ WorkspaceId: workspaceId, diff --git a/internal/pipelines_test.go b/internal/pipelines_test.go index bd10ebe35..039220277 100644 --- a/internal/pipelines_test.go +++ b/internal/pipelines_test.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/pipelines" "github.com/databricks/databricks-sdk-go/service/workspace" "github.com/stretchr/testify/assert" @@ -11,7 +12,7 @@ import ( ) func TestAccPipelines(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) notebookPath := myNotebookPath(t, w) err := w.Workspace.Import(ctx, workspace.Import{ @@ -25,7 +26,7 @@ func TestAccPipelines(t *testing.T) { created, err := w.Pipelines.Create(ctx, pipelines.CreatePipeline{ Continuous: false, - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), Libraries: []pipelines.PipelineLibrary{ { Notebook: &pipelines.NotebookLibrary{ @@ -35,7 +36,7 @@ func TestAccPipelines(t *testing.T) { }, Clusters: []pipelines.PipelineCluster{ { - InstancePoolId: GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), + InstancePoolId: qa.GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), Label: "default", NumWorkers: 1, CustomTags: map[string]string{ @@ -57,7 +58,7 @@ func TestAccPipelines(t *testing.T) { err = w.Pipelines.Update(ctx, pipelines.EditPipeline{ PipelineId: created.PipelineId, - Name: RandomName("go-sdk-updated-"), + Name: qa.RandomName("go-sdk-updated-"), Libraries: []pipelines.PipelineLibrary{ { Notebook: &pipelines.NotebookLibrary{ @@ -67,7 +68,7 @@ func TestAccPipelines(t *testing.T) { }, Clusters: []pipelines.PipelineCluster{ { - InstancePoolId: GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), + InstancePoolId: qa.GetEnvOrSkipTest(t, "TEST_INSTANCE_POOL_ID"), Label: "default", NumWorkers: 1, CustomTags: map[string]string{ diff --git a/internal/repos_test.go b/internal/repos_test.go index 0511ed370..34fa115fe 100644 --- a/internal/repos_test.go +++ b/internal/repos_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/settings" "github.com/databricks/databricks-sdk-go/service/workspace" "github.com/stretchr/testify/assert" @@ -11,7 +12,7 @@ import ( ) func TestAccRepos(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) // Skip this test if "Files in Repos" is not enabled. conf, err := w.WorkspaceConf.GetStatus(ctx, settings.GetStatusRequest{ @@ -23,7 +24,7 @@ func TestAccRepos(t *testing.T) { } // Synthesize unique path for this checkout in this user's home. - root := RandomName(fmt.Sprintf("/Repos/%s/tf-", me(t, w).UserName)) + root := qa.RandomName(fmt.Sprintf("/Repos/%s/tf-", me(t, w).UserName)) ri, err := w.Repos.Create(ctx, workspace.CreateRepo{ Path: root, Url: "https://github.com/shreyas-goenka/empty-repo.git", diff --git a/internal/scim_test.go b/internal/scim_test.go index 61355b476..9c564e4e7 100644 --- a/internal/scim_test.go +++ b/internal/scim_test.go @@ -6,6 +6,7 @@ import ( "github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go/apierr" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/iam" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -19,7 +20,7 @@ func me(t *testing.T, w *databricks.WorkspaceClient) *iam.User { } func TestAccCurrentUser(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) me, err := w.CurrentUser.Me(ctx) require.NoError(t, err) @@ -28,12 +29,12 @@ func TestAccCurrentUser(t *testing.T) { } func TestAccUsers(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) // create new user user, err := w.Users.Create(ctx, iam.User{ - DisplayName: RandomName("Me "), - UserName: RandomEmail(), + DisplayName: qa.RandomName("Me "), + UserName: qa.RandomEmail(), }) require.NoError(t, err) @@ -72,11 +73,11 @@ func TestAccUsers(t *testing.T) { } func TestAccGroups(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) // create new group group, err := w.Groups.Create(ctx, iam.Group{ - DisplayName: RandomName("go-sdk-"), + DisplayName: qa.RandomName("go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { @@ -112,13 +113,13 @@ func TestAccGroups(t *testing.T) { } func TestAccServicePrincipalsOnAWS(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) if !w.Config.IsAws() { t.Skip("test only for aws") } created, err := w.ServicePrincipals.Create(ctx, iam.ServicePrincipal{ - DisplayName: RandomName("go-sdk-"), + DisplayName: qa.RandomName("go-sdk-"), }) require.NoError(t, err) @@ -128,7 +129,7 @@ func TestAccServicePrincipalsOnAWS(t *testing.T) { }) err = w.ServicePrincipals.Update(ctx, iam.ServicePrincipal{ Id: created.Id, - DisplayName: RandomName("go-sdk-updated-"), + DisplayName: qa.RandomName("go-sdk-updated-"), Roles: []iam.ComplexValue{ { Value: "xyz", diff --git a/internal/secrets_test.go b/internal/secrets_test.go index ba26aaa0e..452a80d5b 100644 --- a/internal/secrets_test.go +++ b/internal/secrets_test.go @@ -3,6 +3,7 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/iam" "github.com/databricks/databricks-sdk-go/service/workspace" "github.com/stretchr/testify/assert" @@ -10,10 +11,10 @@ import ( ) func TestAccSecrets(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) - scopeName := RandomName("scope-") - keyName := RandomName("key-") + scopeName := qa.RandomName("scope-") + keyName := qa.RandomName("key-") // creates scopeName err := w.Secrets.CreateScope(ctx, workspace.CreateScope{ @@ -33,7 +34,7 @@ func TestAccSecrets(t *testing.T) { err = w.Secrets.PutSecret(ctx, workspace.PutSecret{ Scope: scopeName, Key: keyName, - StringValue: RandomName("dummy"), + StringValue: qa.RandomName("dummy"), }) require.NoError(t, err) t.Cleanup(func() { @@ -49,7 +50,7 @@ func TestAccSecrets(t *testing.T) { assert.True(t, len(scrts.Secrets) == 1) group, err := w.Groups.Create(ctx, iam.Group{ - DisplayName: RandomName("go-sdk-"), + DisplayName: qa.RandomName("go-sdk-"), }) require.NoError(t, err) t.Cleanup(func() { diff --git a/internal/sharing_test.go b/internal/sharing_test.go index 670e58164..c55f37b43 100644 --- a/internal/sharing_test.go +++ b/internal/sharing_test.go @@ -6,6 +6,7 @@ import ( "strings" "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/catalog" "github.com/databricks/databricks-sdk-go/service/sharing" "github.com/databricks/databricks-sdk-go/service/sql" @@ -14,7 +15,7 @@ import ( ) func TestUcAccProviders(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) // this is a publicly available test token publicShareRecipient := `{ @@ -23,7 +24,7 @@ func TestUcAccProviders(t *testing.T) { "endpoint":"https://sharing.delta.io/delta-sharing/" }` created, err := w.Providers.Create(ctx, sharing.CreateProvider{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), RecipientProfileStr: publicShareRecipient, }) require.NoError(t, err) @@ -54,10 +55,10 @@ func TestUcAccProviders(t *testing.T) { // TODO: remove NoTranspile func TestUcAccRecipientActivationNoTranspile(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) created, err := w.Recipients.Create(ctx, sharing.CreateRecipient{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), AuthenticationType: sharing.AuthenticationTypeToken, }) require.NoError(t, err) @@ -74,7 +75,7 @@ func TestUcAccRecipientActivationNoTranspile(t *testing.T) { require.NoError(t, err) newProvider, err := w.Providers.Create(ctx, sharing.CreateProvider{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), RecipientProfileStr: string(recipientProfileStr), }) require.NoError(t, err) @@ -90,10 +91,10 @@ func TestUcAccRecipientActivationNoTranspile(t *testing.T) { } func TestUcAccRecipients(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) created, err := w.Recipients.Create(ctx, sharing.CreateRecipient{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), }) require.NoError(t, err) @@ -103,7 +104,7 @@ func TestUcAccRecipients(t *testing.T) { }) err = w.Recipients.Update(ctx, sharing.UpdateRecipient{ Name: created.Name, - Comment: RandomName("comment "), + Comment: qa.RandomName("comment "), }) require.NoError(t, err) @@ -127,10 +128,10 @@ func TestUcAccRecipients(t *testing.T) { } func TestUcAccShares(t *testing.T) { - ctx, w := ucwsTest(t) + ctx, w := qa.UcwsTest(t) createdCatalog, err := w.Catalogs.Create(ctx, catalog.CreateCatalog{ - Name: RandomName("catalog_"), + Name: qa.RandomName("catalog_"), }) require.NoError(t, err) t.Cleanup(func() { @@ -142,7 +143,7 @@ func TestUcAccShares(t *testing.T) { }) createdSchema, err := w.Schemas.Create(ctx, catalog.CreateSchema{ - Name: RandomName("schema_"), + Name: qa.RandomName("schema_"), CatalogName: createdCatalog.Name, }) require.NoError(t, err) @@ -151,12 +152,12 @@ func TestUcAccShares(t *testing.T) { require.NoError(t, err) }) - tableName := RandomName("foo_") + tableName := qa.RandomName("foo_") tableFullName := fmt.Sprintf("%s.%s.%s", createdCatalog.Name, createdSchema.Name, tableName) // creates tableName _, err = w.StatementExecution.ExecuteAndWait(ctx, sql.ExecuteStatementRequest{ - WarehouseId: GetEnvOrSkipTest(t, "TEST_DEFAULT_WAREHOUSE_ID"), + WarehouseId: qa.GetEnvOrSkipTest(t, "TEST_DEFAULT_WAREHOUSE_ID"), Catalog: createdCatalog.Name, Schema: createdSchema.Name, Statement: fmt.Sprintf("CREATE TABLE %s AS SELECT 2+2 as four", tableName), @@ -168,7 +169,7 @@ func TestUcAccShares(t *testing.T) { }) createdShare, err := w.Shares.Create(ctx, sharing.CreateShare{ - Name: RandomName("sdk-"), + Name: qa.RandomName("sdk-"), }) require.NoError(t, err) t.Cleanup(func() { diff --git a/internal/tokenmanagement_test.go b/internal/tokenmanagement_test.go index 0fc7bc5d9..7a029d880 100644 --- a/internal/tokenmanagement_test.go +++ b/internal/tokenmanagement_test.go @@ -3,6 +3,7 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/iam" "github.com/databricks/databricks-sdk-go/service/settings" "github.com/stretchr/testify/assert" @@ -10,7 +11,7 @@ import ( ) func TestAccCreateOboTokenOnAws(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) if !w.Config.IsAws() { t.Skip("works only on aws") } @@ -18,7 +19,7 @@ func TestAccCreateOboTokenOnAws(t *testing.T) { require.NoError(t, err) spn, err := w.ServicePrincipals.Create(ctx, iam.ServicePrincipal{ - DisplayName: RandomName(t.Name()), + DisplayName: qa.RandomName(t.Name()), Groups: []iam.ComplexValue{ { Value: groups["admins"], diff --git a/internal/tokens_test.go b/internal/tokens_test.go index a371b6528..9d4e07859 100644 --- a/internal/tokens_test.go +++ b/internal/tokens_test.go @@ -4,16 +4,17 @@ import ( "testing" "github.com/databricks/databricks-sdk-go" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/settings" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccTokens(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) token, err := w.Tokens.Create(ctx, settings.CreateTokenRequest{ - Comment: RandomName("go-sdk-"), + Comment: qa.RandomName("go-sdk-"), LifetimeSeconds: 300, }) require.NoError(t, err) diff --git a/internal/warehouses_test.go b/internal/warehouses_test.go index 4c3d5359f..045ccce7f 100644 --- a/internal/warehouses_test.go +++ b/internal/warehouses_test.go @@ -3,16 +3,17 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/sql" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccSqlWarehouses(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) created, err := w.Warehouses.CreateAndWait(ctx, sql.CreateWarehouseRequest{ - Name: RandomName("go-sdk-"), + Name: qa.RandomName("go-sdk-"), ClusterSize: "2X-Small", MaxNumClusters: 1, AutoStopMins: 10, @@ -26,7 +27,7 @@ func TestAccSqlWarehouses(t *testing.T) { _, err = w.Warehouses.Edit(ctx, sql.EditWarehouseRequest{ Id: created.Id, - Name: RandomName("go-sdk-updated-"), + Name: qa.RandomName("go-sdk-updated-"), ClusterSize: "2X-Small", MaxNumClusters: 1, AutoStopMins: 10, diff --git a/internal/workspace_test.go b/internal/workspace_test.go index 9485697e6..4c22fe640 100644 --- a/internal/workspace_test.go +++ b/internal/workspace_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/databricks/databricks-sdk-go" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/workspace" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -15,8 +16,8 @@ import ( func myNotebookPath(t *testing.T, w *databricks.WorkspaceClient) string { ctx := context.Background() - testDir := filepath.Join("/Users", me(t, w).UserName, ".sdk", RandomName("t-")) - notebook := filepath.Join(testDir, RandomName("n-")) + testDir := filepath.Join("/Users", me(t, w).UserName, ".sdk", qa.RandomName("t-")) + notebook := filepath.Join(testDir, qa.RandomName("n-")) err := w.Workspace.MkdirsByPath(ctx, testDir) require.NoError(t, err) @@ -32,7 +33,7 @@ func myNotebookPath(t *testing.T, w *databricks.WorkspaceClient) string { } func TestAccWorkspaceIntegration(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) notebook := myNotebookPath(t, w) // Import the test notebook @@ -76,9 +77,9 @@ func TestAccWorkspaceIntegration(t *testing.T) { func TestAccWorkspaceUploadNotebookWithFileExtensionNoTranspile(t *testing.T) { // TODO: remove NoTranspile suffix once other languages get Upload/Donwload features - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) - notebookPath := filepath.Join("/Users", me(t, w).UserName, RandomName("notebook-")+".py") + notebookPath := filepath.Join("/Users", me(t, w).UserName, qa.RandomName("notebook-")+".py") err := w.Workspace.Upload(ctx, notebookPath, strings.NewReader("print(1)")) assert.NoError(t, err) @@ -102,9 +103,9 @@ func TestAccWorkspaceUploadNotebookWithFileExtensionNoTranspile(t *testing.T) { func TestAccWorkspaceUploadNotebookWithFileNoExtensionNoTranspile(t *testing.T) { // TODO: remove NoTranspile suffix once other languages get Upload/Donwload features - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) - notebookPath := filepath.Join("/Users", me(t, w).UserName, RandomName("notebook-")) + notebookPath := filepath.Join("/Users", me(t, w).UserName, qa.RandomName("notebook-")) err := w.Workspace.Upload(ctx, notebookPath, strings.NewReader("print(1)"), workspace.UploadLanguage(workspace.LanguagePython)) @@ -129,9 +130,9 @@ func TestAccWorkspaceUploadNotebookWithFileNoExtensionNoTranspile(t *testing.T) func TestAccWorkspaceUploadFileNoTranspile(t *testing.T) { // TODO: remove NoTranspile suffix once other languages get Upload/Donwload features - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) - txtPath := filepath.Join("/Users", me(t, w).UserName, RandomName("txt-")) + txtPath := filepath.Join("/Users", me(t, w).UserName, qa.RandomName("txt-")) err := w.Workspace.Upload(ctx, txtPath, strings.NewReader("print(1)"), workspace.UploadFormat(workspace.ImportFormatAuto)) @@ -154,7 +155,7 @@ func TestAccWorkspaceUploadFileNoTranspile(t *testing.T) { } func TestAccWorkspaceRecursiveListNoTranspile(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) notebook := myNotebookPath(t, w) // Import the test notebook diff --git a/internal/workspaceconf_test.go b/internal/workspaceconf_test.go index 40fc8b5cf..5be302ae2 100644 --- a/internal/workspaceconf_test.go +++ b/internal/workspaceconf_test.go @@ -3,13 +3,14 @@ package internal import ( "testing" + "github.com/databricks/databricks-sdk-go/qa" "github.com/databricks/databricks-sdk-go/service/settings" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAccWorkspaceConf(t *testing.T) { - ctx, w := workspaceTest(t) + ctx, w := qa.WorkspaceTest(t) conf, err := w.WorkspaceConf.GetStatus(ctx, settings.GetStatusRequest{ Keys: "maxTokenLifetimeDays,enableIpAccessLists,enableWorkspaceFilesystem", }) diff --git a/internal/init_test.go b/qa/init.go similarity index 89% rename from internal/init_test.go rename to qa/init.go index 743f04f79..12a50976a 100644 --- a/internal/init_test.go +++ b/qa/init.go @@ -1,4 +1,4 @@ -package internal +package qa import ( "context" @@ -28,8 +28,8 @@ func init() { } } -// prelude for all workspace-level tests -func workspaceTest(t *testing.T) (context.Context, *databricks.WorkspaceClient) { +// WorkspaceTest is the prelude for all workspace-level tests +func WorkspaceTest(t *testing.T) (context.Context, *databricks.WorkspaceClient) { loadDebugEnvIfRunsFromIDE(t, "workspace") t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) if os.Getenv("DATABRICKS_ACCOUNT_ID") != "" { @@ -40,8 +40,8 @@ func workspaceTest(t *testing.T) (context.Context, *databricks.WorkspaceClient) return ctx, databricks.Must(databricks.NewWorkspaceClient()) } -// prelude for all workspace-level UC tests -func ucwsTest(t *testing.T) (context.Context, *databricks.WorkspaceClient) { +// UcwsTest is the prelude for all workspace-level UC tests +func UcwsTest(t *testing.T) (context.Context, *databricks.WorkspaceClient) { loadDebugEnvIfRunsFromIDE(t, "ucws") if os.Getenv("DATABRICKS_ACCOUNT_ID") != "" { skipf(t)("Skipping workspace test on account level") @@ -52,8 +52,8 @@ func ucwsTest(t *testing.T) (context.Context, *databricks.WorkspaceClient) { return ctx, databricks.Must(databricks.NewWorkspaceClient()) } -// prelude for all account-level tests -func accountTest(t *testing.T) (context.Context, *databricks.AccountClient) { +// AccountTest is the prelude for all account-level tests +func AccountTest(t *testing.T) (context.Context, *databricks.AccountClient) { loadDebugEnvIfRunsFromIDE(t, "account") cfg := &config.Config{ AccountID: GetEnvOrSkipTest(t, "DATABRICKS_ACCOUNT_ID"), @@ -72,8 +72,8 @@ func accountTest(t *testing.T) (context.Context, *databricks.AccountClient) { (*databricks.Config)(cfg))) } -// prelude for all UC account-level tests -func ucacctTest(t *testing.T) (context.Context, *databricks.AccountClient) { +// UcacctTest is the prelude for all UC account-level tests +func UcacctTest(t *testing.T) (context.Context, *databricks.AccountClient) { loadDebugEnvIfRunsFromIDE(t, "ucacct") cfg := &config.Config{ AccountID: GetEnvOrSkipTest(t, "DATABRICKS_ACCOUNT_ID"),