diff --git a/pkg/sdk/testint/accounts_integration_test.go b/pkg/sdk/testint/accounts_integration_test.go index 2f67cab857..2bd7cb035f 100644 --- a/pkg/sdk/testint/accounts_integration_test.go +++ b/pkg/sdk/testint/accounts_integration_test.go @@ -234,9 +234,7 @@ func TestInt_AccountAlter(t *testing.T) { }) t.Run("set and unset password policy", func(t *testing.T) { - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - passwordPolicyTest, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), schemaTest) + passwordPolicyTest, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(passwordPolicyCleanup) opts := &sdk.AlterAccountOptions{ Set: &sdk.AccountSet{ @@ -257,9 +255,7 @@ func TestInt_AccountAlter(t *testing.T) { }) t.Run("set and unset session policy", func(t *testing.T) { - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - sessionPolicyTest, sessionPolicyCleanup := createSessionPolicy(t, client, testDb(t), schemaTest) + sessionPolicyTest, sessionPolicyCleanup := createSessionPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(sessionPolicyCleanup) opts := &sdk.AlterAccountOptions{ Set: &sdk.AccountSet{ @@ -280,11 +276,9 @@ func TestInt_AccountAlter(t *testing.T) { }) t.Run("set and unset tag", func(t *testing.T) { - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - tagTest1, tagCleanup1 := createTag(t, client, testDb(t), schemaTest) + tagTest1, tagCleanup1 := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup1) - tagTest2, tagCleanup2 := createTag(t, client, testDb(t), schemaTest) + tagTest2, tagCleanup2 := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup2) opts := &sdk.AlterAccountOptions{ diff --git a/pkg/sdk/testint/alerts_integration_test.go b/pkg/sdk/testint/alerts_integration_test.go index 05d410df9b..d12dbdf839 100644 --- a/pkg/sdk/testint/alerts_integration_test.go +++ b/pkg/sdk/testint/alerts_integration_test.go @@ -14,16 +14,13 @@ func TestInt_AlertsShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - testWarehouse, warehouseCleanup := createWarehouse(t, client) t.Cleanup(warehouseCleanup) - alertTest, alertCleanup := createAlert(t, client, testDb(t), schemaTest, testWarehouse) + alertTest, alertCleanup := createAlert(t, client, testDb(t), testSchema(t), testWarehouse) t.Cleanup(alertCleanup) - alert2Test, alert2Cleanup := createAlert(t, client, testDb(t), schemaTest, testWarehouse) + alert2Test, alert2Cleanup := createAlert(t, client, testDb(t), testSchema(t), testWarehouse) t.Cleanup(alert2Cleanup) t.Run("without show options", func(t *testing.T) { @@ -35,7 +32,7 @@ func TestInt_AlertsShow(t *testing.T) { t.Run("with show options", func(t *testing.T) { showOptions := &sdk.ShowAlertOptions{ In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, } alerts, err := client.Alerts.Show(ctx, showOptions) @@ -74,7 +71,7 @@ func TestInt_AlertsShow(t *testing.T) { t.Run("when limiting the number of results", func(t *testing.T) { showOptions := &sdk.ShowAlertOptions{ In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, Limit: sdk.Int(1), } @@ -88,9 +85,6 @@ func TestInt_AlertCreate(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - testWarehouse, warehouseCleanup := createWarehouse(t, client) t.Cleanup(warehouseCleanup) @@ -100,7 +94,7 @@ func TestInt_AlertCreate(t *testing.T) { condition := "SELECT 1" action := "SELECT 1" comment := random.Comment() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.Alerts.Create(ctx, id, testWarehouse.ID(), schedule, condition, action, &sdk.CreateAlertOptions{ OrReplace: sdk.Bool(true), IfNotExists: sdk.Bool(false), @@ -121,7 +115,7 @@ func TestInt_AlertCreate(t *testing.T) { Pattern: sdk.String(name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -136,7 +130,7 @@ func TestInt_AlertCreate(t *testing.T) { condition := "SELECT 1" action := "SELECT 1" comment := random.Comment() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.Alerts.Create(ctx, id, testWarehouse.ID(), schedule, condition, action, &sdk.CreateAlertOptions{ OrReplace: sdk.Bool(false), IfNotExists: sdk.Bool(true), @@ -157,7 +151,7 @@ func TestInt_AlertCreate(t *testing.T) { Pattern: sdk.String(name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -171,7 +165,7 @@ func TestInt_AlertCreate(t *testing.T) { schedule := "USING CRON * * * * TUE,THU UTC" condition := "SELECT 1" action := "SELECT 1" - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.Alerts.Create(ctx, id, testWarehouse.ID(), schedule, condition, action, nil) require.NoError(t, err) alertDetails, err := client.Alerts.Describe(ctx, id) @@ -187,7 +181,7 @@ func TestInt_AlertCreate(t *testing.T) { Pattern: sdk.String(name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -209,7 +203,7 @@ func TestInt_AlertCreate(t *testing.T) { 2 end ` - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.Alerts.Create(ctx, id, testWarehouse.ID(), schedule, condition, action, nil) require.NoError(t, err) alertDetails, err := client.Alerts.Describe(ctx, id) @@ -225,7 +219,7 @@ func TestInt_AlertCreate(t *testing.T) { Pattern: sdk.String(name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -239,13 +233,10 @@ func TestInt_AlertDescribe(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - warehouseTest, warehouseCleanup := createWarehouse(t, client) t.Cleanup(warehouseCleanup) - alert, alertCleanup := createAlert(t, client, testDb(t), schemaTest, warehouseTest) + alert, alertCleanup := createAlert(t, client, testDb(t), testSchema(t), warehouseTest) t.Cleanup(alertCleanup) t.Run("when alert exists", func(t *testing.T) { @@ -255,7 +246,7 @@ func TestInt_AlertDescribe(t *testing.T) { }) t.Run("when alert does not exist", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, "does_not_exist") + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist") _, err := client.Alerts.Describe(ctx, id) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) @@ -265,14 +256,11 @@ func TestInt_AlertAlter(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - warehouseTest, warehouseCleanup := createWarehouse(t, client) t.Cleanup(warehouseCleanup) t.Run("when setting and unsetting a value", func(t *testing.T) { - alert, alertCleanup := createAlert(t, client, testDb(t), schemaTest, warehouseTest) + alert, alertCleanup := createAlert(t, client, testDb(t), testSchema(t), warehouseTest) t.Cleanup(alertCleanup) newSchedule := "USING CRON * * * * TUE,FRI GMT" @@ -289,7 +277,7 @@ func TestInt_AlertAlter(t *testing.T) { Pattern: sdk.String(alert.Name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -298,7 +286,7 @@ func TestInt_AlertAlter(t *testing.T) { }) t.Run("when modifying condition and action", func(t *testing.T) { - alert, alertCleanup := createAlert(t, client, testDb(t), schemaTest, warehouseTest) + alert, alertCleanup := createAlert(t, client, testDb(t), testSchema(t), warehouseTest) t.Cleanup(alertCleanup) newCondition := "select * from DUAL where false" @@ -313,7 +301,7 @@ func TestInt_AlertAlter(t *testing.T) { Pattern: sdk.String(alert.Name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -333,7 +321,7 @@ func TestInt_AlertAlter(t *testing.T) { Pattern: sdk.String(alert.Name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -342,7 +330,7 @@ func TestInt_AlertAlter(t *testing.T) { }) t.Run("resume and then suspend", func(t *testing.T) { - alert, alertCleanup := createAlert(t, client, testDb(t), schemaTest, warehouseTest) + alert, alertCleanup := createAlert(t, client, testDb(t), testSchema(t), warehouseTest) t.Cleanup(alertCleanup) alterOptions := &sdk.AlterAlertOptions{ @@ -356,7 +344,7 @@ func TestInt_AlertAlter(t *testing.T) { Pattern: sdk.String(alert.Name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -374,7 +362,7 @@ func TestInt_AlertAlter(t *testing.T) { Pattern: sdk.String(alert.Name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -387,14 +375,11 @@ func TestInt_AlertDrop(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - warehouseTest, warehouseCleanup := createWarehouse(t, client) t.Cleanup(warehouseCleanup) t.Run("when alert exists", func(t *testing.T) { - alert, _ := createAlert(t, client, testDb(t), schemaTest, warehouseTest) + alert, _ := createAlert(t, client, testDb(t), testSchema(t), warehouseTest) id := alert.ID() err := client.Alerts.Drop(ctx, id) require.NoError(t, err) @@ -403,7 +388,7 @@ func TestInt_AlertDrop(t *testing.T) { }) t.Run("when alert does not exist", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, "does_not_exist") + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist") err := client.Alerts.Drop(ctx, id) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) diff --git a/pkg/sdk/testint/context_functions_integration_test.go b/pkg/sdk/testint/context_functions_integration_test.go index 8d025a38ef..aa5b130cc5 100644 --- a/pkg/sdk/testint/context_functions_integration_test.go +++ b/pkg/sdk/testint/context_functions_integration_test.go @@ -65,6 +65,7 @@ func TestInt_CurrentSchema(t *testing.T) { client := testClient(t) ctx := testContext(t) + // new database and schema created on purpose databaseTest, databaseCleanup := createDatabase(t, client) t.Cleanup(databaseCleanup) schemaTest, schemaCleanup := createSchema(t, client, databaseTest) diff --git a/pkg/sdk/testint/databases_integration_test.go b/pkg/sdk/testint/databases_integration_test.go index 48d3832e93..07ac07f5ed 100644 --- a/pkg/sdk/testint/databases_integration_test.go +++ b/pkg/sdk/testint/databases_integration_test.go @@ -53,6 +53,7 @@ func TestInt_DatabasesCreate(t *testing.T) { t.Run("complete", func(t *testing.T) { databaseID := sdk.RandomAccountObjectIdentifier() + // new database and schema created on purpose databaseTest, databaseCleanup := createDatabase(t, client) t.Cleanup(databaseCleanup) schemaTest, schemaCleanup := createSchema(t, client, databaseTest) @@ -185,6 +186,8 @@ this test keeps failing need to fix. */ func TestInt_DatabasesDescribe(t *testing.T) { client := testClient(t) + + // new database and schema created on purpose databaseTest, databaseCleanup := createDatabase(t, client) t.Cleanup(databaseCleanup) schemaTest, schemaCleanup := createSchema(t, client, databaseTest) diff --git a/pkg/sdk/testint/dynamic_table_integration_test.go b/pkg/sdk/testint/dynamic_table_integration_test.go index 00c4723041..cd8ec42227 100644 --- a/pkg/sdk/testint/dynamic_table_integration_test.go +++ b/pkg/sdk/testint/dynamic_table_integration_test.go @@ -15,14 +15,12 @@ func TestInt_DynamicTableCreateAndDrop(t *testing.T) { warehouseTest, warehouseCleanup := createWarehouse(t, client) t.Cleanup(warehouseCleanup) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - tableTest, tableCleanup := createTable(t, client, testDb(t), schemaTest) + tableTest, tableCleanup := createTable(t, client, testDb(t), testSchema(t)) t.Cleanup(tableCleanup) ctx := context.Background() t.Run("test complete", func(t *testing.T) { - name := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, random.String()) + name := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) targetLag := sdk.TargetLag{ MaximumDuration: sdk.String("2 minutes"), } @@ -45,7 +43,7 @@ func TestInt_DynamicTableCreateAndDrop(t *testing.T) { }) t.Run("test complete with target lag", func(t *testing.T) { - name := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, random.String()) + name := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) targetLag := sdk.TargetLag{ Downstream: sdk.Bool(true), } diff --git a/pkg/sdk/testint/external_tables_integration_test.go b/pkg/sdk/testint/external_tables_integration_test.go index c1ac202aac..13ef6d55ac 100644 --- a/pkg/sdk/testint/external_tables_integration_test.go +++ b/pkg/sdk/testint/external_tables_integration_test.go @@ -15,13 +15,11 @@ func TestInt_ExternalTables(t *testing.T) { client := testClient(t) ctx := testContext(t) - schema, _ := createSchema(t, client, testDb(t)) - stageID := sdk.NewAccountObjectIdentifier("EXTERNAL_TABLE_STAGE") stageLocation := "@external_table_stage" _, _ = createStageWithURL(t, client, stageID, nycWeatherDataURL) - tag, _ := createTag(t, client, testDb(t), schema) + tag, _ := createTag(t, client, testDb(t), testSchema(t)) defaultColumns := func() []*sdk.ExternalTableColumnRequest { return []*sdk.ExternalTableColumnRequest{ @@ -40,7 +38,7 @@ func TestInt_ExternalTables(t *testing.T) { minimalCreateExternalTableReq := func(name string) *sdk.CreateExternalTableRequest { return sdk.NewCreateExternalTableRequest( - sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name), + sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name), stageLocation, sdk.NewExternalTableFileFormatRequest().WithFileFormatType(&sdk.ExternalTableFileFormatTypeJSON), ) @@ -48,7 +46,7 @@ func TestInt_ExternalTables(t *testing.T) { createExternalTableWithManualPartitioningReq := func(name string) *sdk.CreateWithManualPartitioningExternalTableRequest { return sdk.NewCreateWithManualPartitioningExternalTableRequest( - sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name), + sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name), stageLocation, sdk.NewExternalTableFileFormatRequest().WithFileFormatType(&sdk.ExternalTableFileFormatTypeJSON), ). @@ -63,7 +61,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Create: minimal", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -74,7 +72,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Create: complete", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.Create( ctx, sdk.NewCreateExternalTableRequest( @@ -100,7 +98,7 @@ func TestInt_ExternalTables(t *testing.T) { }) t.Run("Create: infer schema", func(t *testing.T) { - fileFormat, _ := createFileFormat(t, client, schema.ID()) + fileFormat, _ := createFileFormat(t, client, testSchema(t).ID()) warehouse, warehouseCleanup := createWarehouse(t, client) t.Cleanup(warehouseCleanup) @@ -108,7 +106,7 @@ func TestInt_ExternalTables(t *testing.T) { require.NoError(t, err) name := random.AlphanumericN(32) - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) query := fmt.Sprintf(`SELECT ARRAY_AGG(OBJECT_CONSTRUCT(*)) WITHIN GROUP (ORDER BY order_id) FROM TABLE (INFER_SCHEMA(location => '%s', FILE_FORMAT=>'%s', ignore_case => true))`, stageLocation, fileFormat.ID().FullyQualifiedName()) err = client.ExternalTables.CreateUsingTemplate( ctx, @@ -127,7 +125,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Create with manual partitioning: complete", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.CreateWithManualPartitioning(ctx, createExternalTableWithManualPartitioningReq(name)) require.NoError(t, err) @@ -138,7 +136,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Create delta lake: complete", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.CreateDeltaLake( ctx, sdk.NewCreateDeltaLakeExternalTableRequest( @@ -165,7 +163,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Alter: refresh", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -180,7 +178,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Alter: add files", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.Create( ctx, minimalCreateExternalTableReq(name). @@ -199,7 +197,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Alter: remove files", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.Create( ctx, minimalCreateExternalTableReq(name). @@ -226,7 +224,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Alter: set auto refresh", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -286,7 +284,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Alter: add partitions", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.CreateWithManualPartitioning(ctx, createExternalTableWithManualPartitioningReq(name)) require.NoError(t, err) @@ -302,7 +300,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Alter: drop partitions", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.CreateWithManualPartitioning(ctx, createExternalTableWithManualPartitioningReq(name)) require.NoError(t, err) @@ -327,7 +325,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Drop", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -345,7 +343,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Show", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) @@ -365,7 +363,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Describe: columns", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) req := minimalCreateExternalTableReq(name) err := client.ExternalTables.Create(ctx, req) require.NoError(t, err) @@ -391,7 +389,7 @@ func TestInt_ExternalTables(t *testing.T) { t.Run("Describe: stage", func(t *testing.T) { name := random.AlphanumericN(32) - externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + externalTableID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.ExternalTables.Create(ctx, minimalCreateExternalTableReq(name)) require.NoError(t, err) diff --git a/pkg/sdk/testint/file_format_integration_test.go b/pkg/sdk/testint/file_format_integration_test.go index 97e93b8e7b..7803d2cd37 100644 --- a/pkg/sdk/testint/file_format_integration_test.go +++ b/pkg/sdk/testint/file_format_integration_test.go @@ -13,11 +13,9 @@ import ( func TestInt_FileFormatsCreateAndRead(t *testing.T) { client := testClient(t) ctx := testContext(t) - schema, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) t.Run("CSV", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, random.String()) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeCSV, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -106,7 +104,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { assert.Equal(t, &sdk.CSVEncodingGB18030, describeResult.Options.CSVEncoding) }) t.Run("JSON", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, random.String()) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeJSON, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -178,7 +176,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { assert.Equal(t, true, *describeResult.Options.JSONSkipByteOrderMark) }) t.Run("AVRO", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, random.String()) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeAvro, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -220,7 +218,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { assert.Equal(t, []sdk.NullString{{S: "a"}, {S: "b"}}, *describeResult.Options.AvroNullIf) }) t.Run("ORC", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, random.String()) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeORC, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -259,7 +257,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { assert.Equal(t, []sdk.NullString{{S: "a"}, {S: "b"}}, *describeResult.Options.ORCNullIf) }) t.Run("PARQUET", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, random.String()) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeParquet, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -304,7 +302,7 @@ func TestInt_FileFormatsCreateAndRead(t *testing.T) { assert.Equal(t, []sdk.NullString{{S: "a"}, {S: "b"}}, *describeResult.Options.ParquetNullIf) }) t.Run("XML", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, random.String()) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, random.String()) err := client.FileFormats.Create(ctx, id, &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeXML, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ @@ -360,11 +358,8 @@ func TestInt_FileFormatsAlter(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, cleanupSchema := createSchema(t, client, testDb(t)) - t.Cleanup(cleanupSchema) - t.Run("rename", func(t *testing.T) { - fileFormat, fileFormatCleanup := createFileFormat(t, client, schemaTest.ID()) + fileFormat, fileFormatCleanup := createFileFormat(t, client, testSchema(t).ID()) t.Cleanup(fileFormatCleanup) oldId := fileFormat.ID() newId := sdk.NewSchemaObjectIdentifier(oldId.DatabaseName(), oldId.SchemaName(), random.String()) @@ -393,7 +388,7 @@ func TestInt_FileFormatsAlter(t *testing.T) { }) t.Run("set", func(t *testing.T) { - fileFormat, fileFormatCleanup := createFileFormatWithOptions(t, client, schemaTest.ID(), &sdk.CreateFileFormatOptions{ + fileFormat, fileFormatCleanup := createFileFormatWithOptions(t, client, testSchema(t).ID(), &sdk.CreateFileFormatOptions{ Type: sdk.FileFormatTypeCSV, FileFormatTypeOptions: sdk.FileFormatTypeOptions{ CSVCompression: &sdk.CSVCompressionAuto, @@ -421,10 +416,8 @@ func TestInt_FileFormatsDrop(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, cleanupSchema := createSchema(t, client, testDb(t)) - t.Cleanup(cleanupSchema) t.Run("no options", func(t *testing.T) { - fileFormat, _ := createFileFormat(t, client, schemaTest.ID()) + fileFormat, _ := createFileFormat(t, client, testSchema(t).ID()) err := client.FileFormats.Drop(ctx, fileFormat.ID(), nil) require.NoError(t, err) @@ -433,7 +426,7 @@ func TestInt_FileFormatsDrop(t *testing.T) { }) t.Run("with IfExists", func(t *testing.T) { - fileFormat, _ := createFileFormat(t, client, schemaTest.ID()) + fileFormat, _ := createFileFormat(t, client, testSchema(t).ID()) err := client.FileFormats.Drop(ctx, fileFormat.ID(), &sdk.DropFileFormatOptions{ IfExists: sdk.Bool(true), }) @@ -448,11 +441,9 @@ func TestInt_FileFormatsShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, cleanupSchema := createSchema(t, client, testDb(t)) - t.Cleanup(cleanupSchema) - fileFormatTest, cleanupFileFormat := createFileFormat(t, client, schemaTest.ID()) + fileFormatTest, cleanupFileFormat := createFileFormat(t, client, testSchema(t).ID()) t.Cleanup(cleanupFileFormat) - fileFormatTest2, cleanupFileFormat2 := createFileFormat(t, client, schemaTest.ID()) + fileFormatTest2, cleanupFileFormat2 := createFileFormat(t, client, testSchema(t).ID()) t.Cleanup(cleanupFileFormat2) t.Run("without options", func(t *testing.T) { @@ -477,7 +468,7 @@ func TestInt_FileFormatsShow(t *testing.T) { t.Run("IN", func(t *testing.T) { fileFormats, err := client.FileFormats.Show(ctx, &sdk.ShowFileFormatsOptions{ In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -491,11 +482,10 @@ func TestInt_FileFormatsShowById(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, cleanupSchema := createSchema(t, client, testDb(t)) - t.Cleanup(cleanupSchema) - fileFormatTest, cleanupFileFormat := createFileFormat(t, client, schemaTest.ID()) + fileFormatTest, cleanupFileFormat := createFileFormat(t, client, testSchema(t).ID()) t.Cleanup(cleanupFileFormat) + // new database and schema created on purpose databaseTest2, cleanupDatabase2 := createDatabase(t, client) t.Cleanup(cleanupDatabase2) schemaTest2, cleanupSchema2 := createSchema(t, client, databaseTest2) @@ -510,7 +500,7 @@ func TestInt_FileFormatsShowById(t *testing.T) { fileFormat, err := client.FileFormats.ShowByID(ctx, fileFormatTest.ID()) require.NoError(t, err) assert.Equal(t, testDb(t).Name, fileFormat.Name.DatabaseName()) - assert.Equal(t, schemaTest.Name, fileFormat.Name.SchemaName()) + assert.Equal(t, testSchema(t).Name, fileFormat.Name.SchemaName()) assert.Equal(t, fileFormatTest.Name.Name(), fileFormat.Name.Name()) }) } diff --git a/pkg/sdk/testint/grants_integration_test.go b/pkg/sdk/testint/grants_integration_test.go index 003017ffee..e550f1d791 100644 --- a/pkg/sdk/testint/grants_integration_test.go +++ b/pkg/sdk/testint/grants_integration_test.go @@ -97,14 +97,12 @@ func TestInt_GrantAndRevokePrivilegesToAccountRole(t *testing.T) { t.Run("on schema", func(t *testing.T) { roleTest, roleCleanup := createRole(t, client) t.Cleanup(roleCleanup) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) privileges := &sdk.AccountRoleGrantPrivileges{ SchemaPrivileges: []sdk.SchemaPrivilege{sdk.SchemaPrivilegeCreateAlert}, } on := &sdk.AccountRoleGrantOn{ Schema: &sdk.GrantOnSchema{ - Schema: sdk.Pointer(schemaTest.ID()), + Schema: sdk.Pointer(testSchema(t).ID()), }, } err := client.Grants.GrantPrivilegesToAccountRole(ctx, privileges, on, roleTest.ID(), nil) @@ -133,9 +131,7 @@ func TestInt_GrantAndRevokePrivilegesToAccountRole(t *testing.T) { t.Run("on schema object", func(t *testing.T) { roleTest, roleCleanup := createRole(t, client) t.Cleanup(roleCleanup) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - tableTest, tableTestCleanup := createTable(t, client, testDb(t), schemaTest) + tableTest, tableTestCleanup := createTable(t, client, testDb(t), testSchema(t)) t.Cleanup(tableTestCleanup) privileges := &sdk.AccountRoleGrantPrivileges{ SchemaObjectPrivileges: []sdk.SchemaObjectPrivilege{sdk.SchemaObjectPrivilegeSelect}, @@ -144,7 +140,7 @@ func TestInt_GrantAndRevokePrivilegesToAccountRole(t *testing.T) { SchemaObject: &sdk.GrantOnSchemaObject{ All: &sdk.GrantOnSchemaObjectIn{ PluralObjectType: sdk.PluralObjectTypeTables, - InSchema: sdk.Pointer(schemaTest.ID()), + InSchema: sdk.Pointer(testSchema(t).ID()), }, }, } @@ -264,14 +260,13 @@ func TestInt_GrantAndRevokePrivilegesToDatabaseRole(t *testing.T) { t.Run("on schema", func(t *testing.T) { databaseRole, _ := createDatabaseRole(t, client, testDb(t)) databaseRoleId := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, databaseRole.Name) - schema, _ := createSchema(t, client, testDb(t)) privileges := &sdk.DatabaseRoleGrantPrivileges{ SchemaPrivileges: []sdk.SchemaPrivilege{sdk.SchemaPrivilegeCreateAlert}, } on := &sdk.DatabaseRoleGrantOn{ Schema: &sdk.GrantOnSchema{ - Schema: sdk.Pointer(schema.ID()), + Schema: sdk.Pointer(testSchema(t).ID()), }, } @@ -313,8 +308,7 @@ func TestInt_GrantAndRevokePrivilegesToDatabaseRole(t *testing.T) { t.Run("on schema object", func(t *testing.T) { databaseRole, _ := createDatabaseRole(t, client, testDb(t)) databaseRoleId := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, databaseRole.Name) - schema, _ := createSchema(t, client, testDb(t)) - table, _ := createTable(t, client, testDb(t), schema) + table, _ := createTable(t, client, testDb(t), testSchema(t)) privileges := &sdk.DatabaseRoleGrantPrivileges{ SchemaObjectPrivileges: []sdk.SchemaObjectPrivilege{sdk.SchemaObjectPrivilegeSelect}, @@ -323,7 +317,7 @@ func TestInt_GrantAndRevokePrivilegesToDatabaseRole(t *testing.T) { SchemaObject: &sdk.GrantOnSchemaObject{ All: &sdk.GrantOnSchemaObjectIn{ PluralObjectType: sdk.PluralObjectTypeTables, - InSchema: sdk.Pointer(schema.ID()), + InSchema: sdk.Pointer(testSchema(t).ID()), }, }, } @@ -481,8 +475,7 @@ func TestInt_GrantOwnership(t *testing.T) { t.Run("on schema object to database role", func(t *testing.T) { databaseRole, _ := createDatabaseRole(t, client, testDb(t)) databaseRoleId := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, databaseRole.Name) - schema, _ := createSchema(t, client, testDb(t)) - table, _ := createTable(t, client, testDb(t), schema) + table, _ := createTable(t, client, testDb(t), testSchema(t)) on := sdk.OwnershipGrantOn{ Object: &sdk.Object{ diff --git a/pkg/sdk/testint/helpers.go b/pkg/sdk/testint/helpers_test.go similarity index 96% rename from pkg/sdk/testint/helpers.go rename to pkg/sdk/testint/helpers_test.go index e19cfaca2b..ce25e7f157 100644 --- a/pkg/sdk/testint/helpers.go +++ b/pkg/sdk/testint/helpers_test.go @@ -63,34 +63,6 @@ func testClientFromProfile(t *testing.T, profile string) (*sdk.Client, error) { return sdk.NewClient(config) } -func useDatabase(t *testing.T, client *sdk.Client, databaseID sdk.AccountObjectIdentifier) func() { - t.Helper() - ctx := context.Background() - orgDB, err := client.ContextFunctions.CurrentDatabase(ctx) - require.NoError(t, err) - err = client.Sessions.UseDatabase(ctx, databaseID) - require.NoError(t, err) - return func() { - err := client.Sessions.UseDatabase(ctx, sdk.NewAccountObjectIdentifier(orgDB)) - require.NoError(t, err) - } -} - -func useSchema(t *testing.T, client *sdk.Client, schemaID sdk.DatabaseObjectIdentifier) func() { - t.Helper() - ctx := context.Background() - orgDB, err := client.ContextFunctions.CurrentDatabase(ctx) - require.NoError(t, err) - orgSchema, err := client.ContextFunctions.CurrentSchema(ctx) - require.NoError(t, err) - err = client.Sessions.UseSchema(ctx, schemaID) - require.NoError(t, err) - return func() { - err := client.Sessions.UseSchema(ctx, sdk.NewDatabaseObjectIdentifier(orgDB, orgSchema)) - require.NoError(t, err) - } -} - func useWarehouse(t *testing.T, client *sdk.Client, warehouseID sdk.AccountObjectIdentifier) func() { t.Helper() ctx := context.Background() @@ -119,6 +91,8 @@ func createDatabaseWithOptions(t *testing.T, client *sdk.Client, id sdk.AccountO return database, func() { err := client.Databases.Drop(ctx, id, nil) require.NoError(t, err) + err = client.Sessions.UseSchema(ctx, testSchema(t).ID()) + require.NoError(t, err) } } @@ -141,6 +115,8 @@ func createSchemaWithIdentifier(t *testing.T, client *sdk.Client, database *sdk. return } require.NoError(t, err) + err = client.Sessions.UseSchema(ctx, testSchema(t).ID()) + require.NoError(t, err) } } diff --git a/pkg/sdk/testint/masking_policy_integration_test.go b/pkg/sdk/testint/masking_policy_integration_test.go index c29dd537de..16d487d27f 100644 --- a/pkg/sdk/testint/masking_policy_integration_test.go +++ b/pkg/sdk/testint/masking_policy_integration_test.go @@ -14,21 +14,13 @@ func TestInt_MaskingPoliciesShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - - maskingPolicyTest, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), schemaTest) + maskingPolicyTest, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(maskingPolicyCleanup) - maskingPolicy2Test, maskingPolicy2Cleanup := createMaskingPolicy(t, client, testDb(t), schemaTest) + maskingPolicy2Test, maskingPolicy2Cleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(maskingPolicy2Cleanup) t.Run("without show options", func(t *testing.T) { - useDatabaseCleanup := useDatabase(t, client, testDb(t).ID()) - t.Cleanup(useDatabaseCleanup) - useSchemaCleanup := useSchema(t, client, schemaTest.ID()) - t.Cleanup(useSchemaCleanup) - maskingPolicies, err := client.MaskingPolicies.Show(ctx, nil) require.NoError(t, err) assert.Equal(t, 2, len(maskingPolicies)) @@ -37,7 +29,7 @@ func TestInt_MaskingPoliciesShow(t *testing.T) { t.Run("with show options", func(t *testing.T) { showOptions := &sdk.ShowMaskingPolicyOptions{ In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, } maskingPolicies, err := client.MaskingPolicies.Show(ctx, showOptions) @@ -93,12 +85,9 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - t.Run("test complete case", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) signature := []sdk.TableColumnSignature{ { Name: "col1", @@ -131,7 +120,7 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { Pattern: sdk.String(name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -143,7 +132,7 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { t.Run("test if_not_exists", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) signature := []sdk.TableColumnSignature{ { Name: "col1", @@ -175,7 +164,7 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { Pattern: sdk.String(name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -187,7 +176,7 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { t.Run("test no options", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) signature := []sdk.TableColumnSignature{ { Name: "col1", @@ -209,7 +198,7 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { Pattern: sdk.String(name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -221,7 +210,7 @@ func TestInt_MaskingPolicyCreate(t *testing.T) { t.Run("test multiline expression", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) signature := []sdk.TableColumnSignature{ { Name: "val", @@ -253,10 +242,7 @@ func TestInt_MaskingPolicyDescribe(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - - maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), schemaTest) + maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(maskingPolicyCleanup) t.Run("when masking policy exists", func(t *testing.T) { @@ -266,7 +252,7 @@ func TestInt_MaskingPolicyDescribe(t *testing.T) { }) t.Run("when masking policy does not exist", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, "does_not_exist") + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist") _, err := client.MaskingPolicies.Describe(ctx, id) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) @@ -276,11 +262,8 @@ func TestInt_MaskingPolicyAlter(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - t.Run("when setting and unsetting a value", func(t *testing.T) { - maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), schemaTest) + maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(maskingPolicyCleanup) comment := random.Comment() alterOptions := &sdk.AlterMaskingPolicyOptions{ @@ -295,7 +278,7 @@ func TestInt_MaskingPolicyAlter(t *testing.T) { Pattern: sdk.String(maskingPolicy.Name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -316,7 +299,7 @@ func TestInt_MaskingPolicyAlter(t *testing.T) { Pattern: sdk.String(maskingPolicy.Name), }, In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, }) require.NoError(t, err) @@ -325,11 +308,11 @@ func TestInt_MaskingPolicyAlter(t *testing.T) { }) t.Run("when renaming", func(t *testing.T) { - maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), schemaTest) + maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) oldID := maskingPolicy.ID() t.Cleanup(maskingPolicyCleanup) newName := random.String() - newID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, newName) + newID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, newName) alterOptions := &sdk.AlterMaskingPolicyOptions{ NewName: &newID, } @@ -347,14 +330,14 @@ func TestInt_MaskingPolicyAlter(t *testing.T) { }) t.Run("setting and unsetting tags", func(t *testing.T) { - maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), schemaTest) + maskingPolicy, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) id := maskingPolicy.ID() t.Cleanup(maskingPolicyCleanup) - tag, tagCleanup := createTag(t, client, testDb(t), schemaTest) + tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup) - tag2, tag2Cleanup := createTag(t, client, testDb(t), schemaTest) + tag2, tag2Cleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tag2Cleanup) tagAssociations := []sdk.TagAssociation{{Name: tag.ID(), Value: "value1"}, {Name: tag2.ID(), Value: "value2"}} @@ -389,11 +372,8 @@ func TestInt_MaskingPolicyDrop(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - t.Run("when masking policy exists", func(t *testing.T) { - maskingPolicy, _ := createMaskingPolicy(t, client, testDb(t), schemaTest) + maskingPolicy, _ := createMaskingPolicy(t, client, testDb(t), testSchema(t)) id := maskingPolicy.ID() err := client.MaskingPolicies.Drop(ctx, id) require.NoError(t, err) @@ -402,7 +382,7 @@ func TestInt_MaskingPolicyDrop(t *testing.T) { }) t.Run("when masking policy does not exist", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, "does_not_exist") + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist") err := client.MaskingPolicies.Drop(ctx, id) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) diff --git a/pkg/sdk/testint/password_policy_integration_test.go b/pkg/sdk/testint/password_policy_integration_test.go index 50044c88e0..de98ec4530 100644 --- a/pkg/sdk/testint/password_policy_integration_test.go +++ b/pkg/sdk/testint/password_policy_integration_test.go @@ -13,13 +13,10 @@ func TestInt_PasswordPoliciesShow(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - - passwordPolicyTest, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), schemaTest) + passwordPolicyTest, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(passwordPolicyCleanup) - passwordPolicy2Test, passwordPolicy2Cleanup := createPasswordPolicy(t, client, testDb(t), schemaTest) + passwordPolicy2Test, passwordPolicy2Cleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(passwordPolicy2Cleanup) t.Run("without show options", func(t *testing.T) { @@ -31,7 +28,7 @@ func TestInt_PasswordPoliciesShow(t *testing.T) { t.Run("with show options", func(t *testing.T) { showOptions := &sdk.ShowPasswordPolicyOptions{ In: &sdk.In{ - Schema: schemaTest.ID(), + Schema: testSchema(t).ID(), }, } passwordPolicies, err := client.PasswordPolicies.Show(ctx, showOptions) @@ -85,11 +82,9 @@ func TestInt_PasswordPolicyCreate(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) t.Run("test complete", func(t *testing.T) { name := random.UUID() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.PasswordPolicies.Create(ctx, id, &sdk.CreatePasswordPolicyOptions{ OrReplace: sdk.Bool(true), PasswordMinLength: sdk.Int(10), @@ -123,7 +118,7 @@ func TestInt_PasswordPolicyCreate(t *testing.T) { t.Run("test if_not_exists", func(t *testing.T) { name := random.UUID() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.PasswordPolicies.Create(ctx, id, &sdk.CreatePasswordPolicyOptions{ OrReplace: sdk.Bool(false), IfNotExists: sdk.Bool(true), @@ -146,7 +141,7 @@ func TestInt_PasswordPolicyCreate(t *testing.T) { t.Run("test no options", func(t *testing.T) { name := random.UUID() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.PasswordPolicies.Create(ctx, id, nil) require.NoError(t, err) passwordPolicyDetails, err := client.PasswordPolicies.Describe(ctx, id) @@ -169,10 +164,7 @@ func TestInt_PasswordPolicyDescribe(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - - passwordPolicy, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), schemaTest) + passwordPolicy, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(passwordPolicyCleanup) t.Run("when password policy exists", func(t *testing.T) { @@ -183,7 +175,7 @@ func TestInt_PasswordPolicyDescribe(t *testing.T) { }) t.Run("when password policy does not exist", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, "does_not_exist") + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist") _, err := client.PasswordPolicies.Describe(ctx, id) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) @@ -193,11 +185,8 @@ func TestInt_PasswordPolicyAlter(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - t.Run("when setting new values", func(t *testing.T) { - passwordPolicy, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), schemaTest) + passwordPolicy, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(passwordPolicyCleanup) alterOptions := &sdk.AlterPasswordPolicyOptions{ Set: &sdk.PasswordPolicySet{ @@ -217,11 +206,11 @@ func TestInt_PasswordPolicyAlter(t *testing.T) { }) t.Run("when renaming", func(t *testing.T) { - passwordPolicy, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), schemaTest) + passwordPolicy, passwordPolicyCleanup := createPasswordPolicy(t, client, testDb(t), testSchema(t)) oldID := passwordPolicy.ID() t.Cleanup(passwordPolicyCleanup) newName := random.UUID() - newID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, newName) + newID := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, newName) alterOptions := &sdk.AlterPasswordPolicyOptions{ NewName: &newID, } @@ -245,7 +234,7 @@ func TestInt_PasswordPolicyAlter(t *testing.T) { // todo [SNOW-928909]: uncomment this once comments are working again // Comment: String("test comment") } - passwordPolicy, passwordPolicyCleanup := createPasswordPolicyWithOptions(t, client, testDb(t), schemaTest, createOptions) + passwordPolicy, passwordPolicyCleanup := createPasswordPolicyWithOptions(t, client, testDb(t), testSchema(t), createOptions) id := passwordPolicy.ID() t.Cleanup(passwordPolicyCleanup) alterOptions := &sdk.AlterPasswordPolicyOptions{ @@ -278,7 +267,7 @@ func TestInt_PasswordPolicyAlter(t *testing.T) { // todo [SNOW-928909]: uncomment this once comments are working again // Comment: String("test comment") } - passwordPolicy, passwordPolicyCleanup := createPasswordPolicyWithOptions(t, client, testDb(t), schemaTest, createOptions) + passwordPolicy, passwordPolicyCleanup := createPasswordPolicyWithOptions(t, client, testDb(t), testSchema(t), createOptions) id := passwordPolicy.ID() t.Cleanup(passwordPolicyCleanup) alterOptions := &sdk.AlterPasswordPolicyOptions{ @@ -298,11 +287,8 @@ func TestInt_PasswordPolicyDrop(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - t.Run("when password policy exists", func(t *testing.T) { - passwordPolicy, _ := createPasswordPolicy(t, client, testDb(t), schemaTest) + passwordPolicy, _ := createPasswordPolicy(t, client, testDb(t), testSchema(t)) id := passwordPolicy.ID() err := client.PasswordPolicies.Drop(ctx, id, nil) require.NoError(t, err) @@ -311,13 +297,13 @@ func TestInt_PasswordPolicyDrop(t *testing.T) { }) t.Run("when password policy does not exist", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schemaTest.Name, "does_not_exist") + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist") err := client.PasswordPolicies.Drop(ctx, id, nil) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) t.Run("when password policy exists and if exists is true", func(t *testing.T) { - passwordPolicy, _ := createPasswordPolicy(t, client, testDb(t), schemaTest) + passwordPolicy, _ := createPasswordPolicy(t, client, testDb(t), testSchema(t)) id := passwordPolicy.ID() dropOptions := &sdk.DropPasswordPolicyOptions{IfExists: sdk.Bool(true)} err := client.PasswordPolicies.Drop(ctx, id, dropOptions) diff --git a/pkg/sdk/testint/pipes_integration_test.go b/pkg/sdk/testint/pipes_integration_test.go index ff8e7320b3..59b13f5080 100644 --- a/pkg/sdk/testint/pipes_integration_test.go +++ b/pkg/sdk/testint/pipes_integration_test.go @@ -20,6 +20,7 @@ func createPipeCopyStatement(t *testing.T, table *sdk.Table, stage *sdk.Stage) s func TestInt_IncorrectCreatePipeBehaviour(t *testing.T) { schemaIdentifier := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, "tcK1>AJ+") + // creating a new schema on purpose schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), schemaIdentifier.Name()) t.Cleanup(schemaCleanup) @@ -43,12 +44,7 @@ func TestInt_IncorrectCreatePipeBehaviour(t *testing.T) { require.ErrorContains(t, err, "unexpected '>'") }) - t.Run("the same works with using db and schema statements", func(t *testing.T) { - useDatabaseCleanup := useDatabase(t, itc.client, testDb(t).ID()) - t.Cleanup(useDatabaseCleanup) - useSchemaCleanup := useSchema(t, itc.client, schema.ID()) - t.Cleanup(useSchemaCleanup) - + t.Run("the same works with using non fully qualified name for table", func(t *testing.T) { createCopyStatementWithoutQualifiersForStage := func(t *testing.T, table *sdk.Table, stage *sdk.Stage) string { t.Helper() require.NotNil(t, table, "table has to be created") @@ -68,29 +64,24 @@ func TestInt_IncorrectCreatePipeBehaviour(t *testing.T) { } func TestInt_PipesShowAndDescribe(t *testing.T) { - schemaIdentifier := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, random.AlphanumericN(12)) - - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), schemaIdentifier.Name()) - t.Cleanup(schemaCleanup) - - table1, table1Cleanup := createTable(t, itc.client, testDb(t), schema) + table1, table1Cleanup := createTable(t, itc.client, testDb(t), testSchema(t)) t.Cleanup(table1Cleanup) - table2, table2Cleanup := createTable(t, itc.client, testDb(t), schema) + table2, table2Cleanup := createTable(t, itc.client, testDb(t), testSchema(t)) t.Cleanup(table2Cleanup) stageName := random.AlphanumericN(20) - stage, stageCleanup := createStage(t, itc.client, testDb(t), schema, stageName) + stage, stageCleanup := createStage(t, itc.client, testDb(t), testSchema(t), stageName) t.Cleanup(stageCleanup) pipe1Name := random.AlphanumericN(20) pipe1CopyStatement := createPipeCopyStatement(t, table1, stage) - pipe1, pipe1Cleanup := createPipe(t, itc.client, testDb(t), schema, pipe1Name, pipe1CopyStatement) + pipe1, pipe1Cleanup := createPipe(t, itc.client, testDb(t), testSchema(t), pipe1Name, pipe1CopyStatement) t.Cleanup(pipe1Cleanup) pipe2Name := random.AlphanumericN(20) pipe2CopyStatement := createPipeCopyStatement(t, table2, stage) - pipe2, pipe2Cleanup := createPipe(t, itc.client, testDb(t), schema, pipe2Name, pipe2CopyStatement) + pipe2, pipe2Cleanup := createPipe(t, itc.client, testDb(t), testSchema(t), pipe2Name, pipe2CopyStatement) t.Cleanup(pipe2Cleanup) t.Run("show: without options", func(t *testing.T) { @@ -105,7 +96,7 @@ func TestInt_PipesShowAndDescribe(t *testing.T) { t.Run("show: in schema", func(t *testing.T) { showOptions := &sdk.ShowPipeOptions{ In: &sdk.In{ - Schema: schema.ID(), + Schema: testSchema(t).ID(), }, } pipes, err := itc.client.Pipes.Show(itc.ctx, showOptions) @@ -157,16 +148,11 @@ func TestInt_PipesShowAndDescribe(t *testing.T) { } func TestInt_PipeCreate(t *testing.T) { - schemaIdentifier := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, random.AlphanumericN(12)) - - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), schemaIdentifier.Name()) - t.Cleanup(schemaCleanup) - - table, tableCleanup := createTable(t, itc.client, testDb(t), schema) + table, tableCleanup := createTable(t, itc.client, testDb(t), testSchema(t)) t.Cleanup(tableCleanup) stageName := random.AlphanumericN(20) - stage, stageCleanup := createStage(t, itc.client, testDb(t), schema, stageName) + stage, stageCleanup := createStage(t, itc.client, testDb(t), testSchema(t), stageName) t.Cleanup(stageCleanup) copyStatement := createPipeCopyStatement(t, table, stage) @@ -176,7 +162,7 @@ func TestInt_PipeCreate(t *testing.T) { assert.NotEmpty(t, pipeDetails.CreatedOn) assert.Equal(t, expectedName, pipeDetails.Name) assert.Equal(t, testDb(t).Name, pipeDetails.DatabaseName) - assert.Equal(t, schema.Name, pipeDetails.SchemaName) + assert.Equal(t, testSchema(t).Name, pipeDetails.SchemaName) assert.Equal(t, copyStatement, pipeDetails.Definition) assert.Equal(t, "ACCOUNTADMIN", pipeDetails.Owner) assert.Empty(t, pipeDetails.NotificationChannel) @@ -191,7 +177,7 @@ func TestInt_PipeCreate(t *testing.T) { // TODO: test error integration, aws sns topic and integration when we have them in project t.Run("test complete case", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) comment := random.Comment() err := itc.client.Pipes.Create(itc.ctx, id, copyStatement, &sdk.CreatePipeOptions{ @@ -210,7 +196,7 @@ func TestInt_PipeCreate(t *testing.T) { t.Run("test if not exists and or replace are incompatible", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := itc.client.Pipes.Create(itc.ctx, id, copyStatement, &sdk.CreatePipeOptions{ OrReplace: sdk.Bool(true), @@ -221,7 +207,7 @@ func TestInt_PipeCreate(t *testing.T) { t.Run("test no options", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := itc.client.Pipes.Create(itc.ctx, id, copyStatement, nil) require.NoError(t, err) @@ -234,22 +220,17 @@ func TestInt_PipeCreate(t *testing.T) { } func TestInt_PipeDrop(t *testing.T) { - schemaIdentifier := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, random.AlphanumericN(12)) - - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), schemaIdentifier.Name()) - t.Cleanup(schemaCleanup) - - table, tableCleanup := createTable(t, itc.client, testDb(t), schema) + table, tableCleanup := createTable(t, itc.client, testDb(t), testSchema(t)) t.Cleanup(tableCleanup) stageName := random.AlphanumericN(20) - stage, stageCleanup := createStage(t, itc.client, testDb(t), schema, stageName) + stage, stageCleanup := createStage(t, itc.client, testDb(t), testSchema(t), stageName) t.Cleanup(stageCleanup) t.Run("pipe exists", func(t *testing.T) { pipeName := random.AlphanumericN(20) pipeCopyStatement := createPipeCopyStatement(t, table, stage) - pipe, _ := createPipe(t, itc.client, testDb(t), schema, pipeName, pipeCopyStatement) + pipe, _ := createPipe(t, itc.client, testDb(t), testSchema(t), pipeName, pipeCopyStatement) err := itc.client.Pipes.Drop(itc.ctx, pipe.ID()) @@ -267,16 +248,11 @@ func TestInt_PipeDrop(t *testing.T) { } func TestInt_PipeAlter(t *testing.T) { - schemaIdentifier := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, random.AlphanumericN(12)) - - schema, schemaCleanup := createSchemaWithIdentifier(t, itc.client, testDb(t), schemaIdentifier.Name()) - t.Cleanup(schemaCleanup) - - table, tableCleanup := createTable(t, itc.client, testDb(t), schema) + table, tableCleanup := createTable(t, itc.client, testDb(t), testSchema(t)) t.Cleanup(tableCleanup) stageName := random.AlphanumericN(20) - stage, stageCleanup := createStage(t, itc.client, testDb(t), schema, stageName) + stage, stageCleanup := createStage(t, itc.client, testDb(t), testSchema(t), stageName) t.Cleanup(stageCleanup) pipeCopyStatement := createPipeCopyStatement(t, table, stage) @@ -284,7 +260,7 @@ func TestInt_PipeAlter(t *testing.T) { // TODO: test error integration when we have them in project t.Run("set value and unset value", func(t *testing.T) { pipeName := random.AlphanumericN(20) - pipe, pipeCleanup := createPipe(t, itc.client, testDb(t), schema, pipeName, pipeCopyStatement) + pipe, pipeCleanup := createPipe(t, itc.client, testDb(t), testSchema(t), pipeName, pipeCopyStatement) t.Cleanup(pipeCleanup) alterOptions := &sdk.AlterPipeOptions{ @@ -319,11 +295,11 @@ func TestInt_PipeAlter(t *testing.T) { }) t.Run("set and unset tag", func(t *testing.T) { - tag, tagCleanup := createTag(t, itc.client, testDb(t), schema) + tag, tagCleanup := createTag(t, itc.client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup) pipeName := random.AlphanumericN(20) - pipe, pipeCleanup := createPipe(t, itc.client, testDb(t), schema, pipeName, pipeCopyStatement) + pipe, pipeCleanup := createPipe(t, itc.client, testDb(t), testSchema(t), pipeName, pipeCopyStatement) t.Cleanup(pipeCleanup) tagValue := "abc" @@ -363,7 +339,7 @@ func TestInt_PipeAlter(t *testing.T) { t.Run("refresh with all", func(t *testing.T) { pipeName := random.AlphanumericN(20) - pipe, pipeCleanup := createPipe(t, itc.client, testDb(t), schema, pipeName, pipeCopyStatement) + pipe, pipeCleanup := createPipe(t, itc.client, testDb(t), testSchema(t), pipeName, pipeCopyStatement) t.Cleanup(pipeCleanup) alterOptions := &sdk.AlterPipeOptions{ diff --git a/pkg/sdk/testint/roles_integration_test.go b/pkg/sdk/testint/roles_integration_test.go index 5c98495952..5e41541e95 100644 --- a/pkg/sdk/testint/roles_integration_test.go +++ b/pkg/sdk/testint/roles_integration_test.go @@ -13,9 +13,8 @@ func TestInt_Roles(t *testing.T) { client := testClient(t) ctx := testContext(t) - schema, _ := createSchema(t, client, testDb(t)) - tag, _ := createTag(t, client, testDb(t), schema) - tag2, _ := createTag(t, client, testDb(t), schema) + tag, _ := createTag(t, client, testDb(t), testSchema(t)) + tag2, _ := createTag(t, client, testDb(t), testSchema(t)) t.Run("create no options", func(t *testing.T) { roleID := sdk.RandomAccountObjectIdentifier() diff --git a/pkg/sdk/testint/schemas_integration_test.go b/pkg/sdk/testint/schemas_integration_test.go index 84d24e4640..a4a8cf351c 100644 --- a/pkg/sdk/testint/schemas_integration_test.go +++ b/pkg/sdk/testint/schemas_integration_test.go @@ -14,6 +14,7 @@ func TestInt_SchemasCreate(t *testing.T) { client := testClient(t) ctx := testContext(t) + // new schema created on purpose schema, cleanupSchema := createSchema(t, client, testDb(t)) t.Cleanup(cleanupSchema) @@ -116,7 +117,12 @@ func TestInt_SchemasAlter(t *testing.T) { ctx := testContext(t) t.Run("rename to", func(t *testing.T) { + // new schema created on purpose schema, _ := createSchema(t, client, testDb(t)) + t.Cleanup(func() { + err := client.Sessions.UseSchema(ctx, testSchema(t).ID()) + require.NoError(t, err) + }) newID := sdk.NewDatabaseObjectIdentifier(testDb(t).Name, random.String()) err := client.Schemas.Alter(ctx, schema.ID(), &sdk.AlterSchemaOptions{ NewName: newID, @@ -132,9 +138,9 @@ func TestInt_SchemasAlter(t *testing.T) { }) t.Run("swap with", func(t *testing.T) { + // new schemas created on purpose schema, cleanupSchema := createSchema(t, client, testDb(t)) t.Cleanup(cleanupSchema) - swapSchema, cleanupSwapSchema := createSchema(t, client, testDb(t)) t.Cleanup(cleanupSwapSchema) @@ -157,6 +163,7 @@ func TestInt_SchemasAlter(t *testing.T) { }) t.Run("set", func(t *testing.T) { + // new schema created on purpose schema, cleanupSchema := createSchema(t, client, testDb(t)) t.Cleanup(cleanupSchema) @@ -274,6 +281,7 @@ func TestInt_SchemasAlter(t *testing.T) { }) t.Run("enable managed access", func(t *testing.T) { + // new schema created on purpose schema, cleanupSchema := createSchema(t, client, testDb(t)) t.Cleanup(cleanupSchema) @@ -293,6 +301,7 @@ func TestInt_SchemasShow(t *testing.T) { client := testClient(t) ctx := testContext(t) + // new schema created on purpose schema, cleanupSchema := createSchema(t, client, testDb(t)) t.Cleanup(cleanupSchema) @@ -334,7 +343,12 @@ func TestInt_SchemasDrop(t *testing.T) { client := testClient(t) ctx := testContext(t) + // new schema created on purpose schema, _ := createSchema(t, client, testDb(t)) + t.Cleanup(func() { + err := client.Sessions.UseSchema(ctx, testSchema(t).ID()) + require.NoError(t, err) + }) s, err := client.Schemas.ShowByID(ctx, schema.ID()) require.NoError(t, err) diff --git a/pkg/sdk/testint/session_policies_gen_integration_test.go b/pkg/sdk/testint/session_policies_gen_integration_test.go index b4904c375a..1f70f2cf15 100644 --- a/pkg/sdk/testint/session_policies_gen_integration_test.go +++ b/pkg/sdk/testint/session_policies_gen_integration_test.go @@ -14,9 +14,6 @@ func TestInt_SessionPolicies(t *testing.T) { client := testClient(t) ctx := testContext(t) - schema, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - assertSessionPolicy := func(t *testing.T, sessionPolicy *sdk.SessionPolicy, id sdk.SchemaObjectIdentifier, expectedComment string) { t.Helper() assert.NotEmpty(t, sessionPolicy.CreatedOn) @@ -52,7 +49,7 @@ func TestInt_SessionPolicies(t *testing.T) { createSessionPolicy := func(t *testing.T) *sdk.SessionPolicy { t.Helper() name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.SessionPolicies.Create(ctx, sdk.NewCreateSessionPolicyRequest(id)) require.NoError(t, err) @@ -66,7 +63,7 @@ func TestInt_SessionPolicies(t *testing.T) { t.Run("create session_policy: complete case", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) comment := random.Comment() request := sdk.NewCreateSessionPolicyRequest(id). @@ -87,7 +84,7 @@ func TestInt_SessionPolicies(t *testing.T) { t.Run("create session_policy: no optionals", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) request := sdk.NewCreateSessionPolicyRequest(id) @@ -103,7 +100,7 @@ func TestInt_SessionPolicies(t *testing.T) { t.Run("drop session_policy: existing", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.SessionPolicies.Create(ctx, sdk.NewCreateSessionPolicyRequest(id)) require.NoError(t, err) @@ -116,7 +113,7 @@ func TestInt_SessionPolicies(t *testing.T) { }) t.Run("drop session_policy: non-existing", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, "does_not_exist") + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist") err := client.SessionPolicies.Drop(ctx, sdk.NewDropSessionPolicyRequest(id)) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) @@ -124,7 +121,7 @@ func TestInt_SessionPolicies(t *testing.T) { t.Run("alter session_policy: set value and unset value", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.SessionPolicies.Create(ctx, sdk.NewCreateSessionPolicyRequest(id)) require.NoError(t, err) @@ -150,11 +147,11 @@ func TestInt_SessionPolicies(t *testing.T) { }) t.Run("set and unset tag", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), schema) + tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup) name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.SessionPolicies.Create(ctx, sdk.NewCreateSessionPolicyRequest(id)) require.NoError(t, err) @@ -191,13 +188,13 @@ func TestInt_SessionPolicies(t *testing.T) { t.Run("alter session_policy: rename", func(t *testing.T) { name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) err := client.SessionPolicies.Create(ctx, sdk.NewCreateSessionPolicyRequest(id)) require.NoError(t, err) newName := random.String() - newId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, newName) + newId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, newName) alterRequest := sdk.NewAlterSessionPolicyRequest(id).WithRenameTo(&newId) err = client.SessionPolicies.Alter(ctx, alterRequest) diff --git a/pkg/sdk/testint/sessions_integration_test.go b/pkg/sdk/testint/sessions_integration_test.go index 8b9d56e496..fa7c283503 100644 --- a/pkg/sdk/testint/sessions_integration_test.go +++ b/pkg/sdk/testint/sessions_integration_test.go @@ -122,17 +122,12 @@ func TestInt_UseWarehouse(t *testing.T) { func TestInt_UseDatabase(t *testing.T) { client := testClient(t) ctx := testContext(t) - originalDB, err := client.ContextFunctions.CurrentDatabase(ctx) - require.NoError(t, err) + t.Cleanup(func() { - originalDBIdentifier := sdk.NewAccountObjectIdentifier(originalDB) - if !sdk.ValidObjectIdentifier(originalDBIdentifier) { - return - } - err := client.Sessions.UseDatabase(ctx, originalDBIdentifier) + err := client.Sessions.UseSchema(ctx, testSchema(t).ID()) require.NoError(t, err) }) - err = client.Sessions.UseDatabase(ctx, testDb(t).ID()) + err := client.Sessions.UseDatabase(ctx, testDb(t).ID()) require.NoError(t, err) actual, err := client.ContextFunctions.CurrentDatabase(ctx) require.NoError(t, err) @@ -143,24 +138,15 @@ func TestInt_UseDatabase(t *testing.T) { func TestInt_UseSchema(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - originalSchema, err := client.ContextFunctions.CurrentSchema(ctx) - require.NoError(t, err) - originalDB, err := client.ContextFunctions.CurrentDatabase(ctx) - require.NoError(t, err) + t.Cleanup(func() { - originalSchemaIdentifier := sdk.NewDatabaseObjectIdentifier(originalDB, originalSchema) - if !sdk.ValidObjectIdentifier(originalSchemaIdentifier) { - return - } - err := client.Sessions.UseSchema(ctx, originalSchemaIdentifier) + err := client.Sessions.UseSchema(ctx, testSchema(t).ID()) require.NoError(t, err) }) - err = client.Sessions.UseSchema(ctx, schemaTest.ID()) + err := client.Sessions.UseSchema(ctx, testSchema(t).ID()) require.NoError(t, err) actual, err := client.ContextFunctions.CurrentSchema(ctx) require.NoError(t, err) - expected := schemaTest.Name + expected := testSchema(t).Name assert.Equal(t, expected, actual) } diff --git a/pkg/sdk/testint/setup_integration_test.go b/pkg/sdk/testint/setup_integration_test.go index c4d6cdd72a..8a99eb484d 100644 --- a/pkg/sdk/testint/setup_integration_test.go +++ b/pkg/sdk/testint/setup_integration_test.go @@ -8,7 +8,7 @@ import ( "time" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" - "github.com/hashicorp/go-uuid" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/random" ) var itc integrationTestContext @@ -42,6 +42,9 @@ func cleanup() { if itc.databaseCleanup != nil { defer itc.databaseCleanup() } + if itc.schemaCleanup != nil { + defer itc.schemaCleanup() + } } type integrationTestContext struct { @@ -50,6 +53,8 @@ type integrationTestContext struct { database *sdk.Database databaseCleanup func() + schema *sdk.Schema + schemaCleanup func() } func (itc *integrationTestContext) initialize() error { @@ -63,19 +68,26 @@ func (itc *integrationTestContext) initialize() error { itc.ctx = context.Background() db, dbCleanup, err := createDb(itc.client, itc.ctx) + if err != nil { + return err + } itc.database = db itc.databaseCleanup = dbCleanup - return err + sc, scCleanup, err := createSc(itc.client, itc.ctx, itc.database) + if err != nil { + return err + } + itc.schema = sc + itc.schemaCleanup = scCleanup + + return nil } func createDb(client *sdk.Client, ctx context.Context) (*sdk.Database, func(), error) { - u, err := uuid.GenerateUUID() - if err != nil { - return nil, nil, err - } - id := sdk.NewAccountObjectIdentifier("int_test_db_" + u) - err = client.Databases.Create(ctx, id, nil) + name := "int_test_db_" + random.UUID() + id := sdk.NewAccountObjectIdentifier(name) + err := client.Databases.Create(ctx, id, nil) if err != nil { return nil, nil, err } @@ -85,6 +97,19 @@ func createDb(client *sdk.Client, ctx context.Context) (*sdk.Database, func(), e }, err } +func createSc(client *sdk.Client, ctx context.Context, db *sdk.Database) (*sdk.Schema, func(), error) { + name := "int_test_sc_" + random.UUID() + id := sdk.NewDatabaseObjectIdentifier(db.Name, name) + err := client.Schemas.Create(ctx, id, nil) + if err != nil { + return nil, nil, err + } + schema, err := client.Schemas.ShowByID(ctx, sdk.NewDatabaseObjectIdentifier(db.Name, name)) + return schema, func() { + _ = client.Schemas.Drop(ctx, id, nil) + }, err +} + // timer measures time from invocation point to the end of method. // It's supposed to be used like: // @@ -96,23 +121,22 @@ func timer(name string) func() { } } -// TODO: Discuss after this initial change is merged. -// This is temporary way to move all integration tests to this package without doing revolution in a single PR. func testClient(t *testing.T) *sdk.Client { t.Helper() return itc.client } -// TODO: Discuss after this initial change is merged. -// This is temporary way to move all integration tests to this package without doing revolution in a single PR. func testContext(t *testing.T) context.Context { t.Helper() return itc.ctx } -// TODO: Discuss after this initial change is merged. -// This is temporary way to move all integration tests to this package without doing revolution in a single PR. func testDb(t *testing.T) *sdk.Database { t.Helper() return itc.database } + +func testSchema(t *testing.T) *sdk.Schema { + t.Helper() + return itc.schema +} diff --git a/pkg/sdk/testint/shares_integration_test.go b/pkg/sdk/testint/shares_integration_test.go index 018cf4554e..1a9724511a 100644 --- a/pkg/sdk/testint/shares_integration_test.go +++ b/pkg/sdk/testint/shares_integration_test.go @@ -283,11 +283,9 @@ func TestInt_SharesAlter(t *testing.T) { require.NoError(t, err) }) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - tagTest, tagCleanup := createTag(t, client, testDb(t), schemaTest) + tagTest, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup) - tagTest2, tagCleanup2 := createTag(t, client, testDb(t), schemaTest) + tagTest2, tagCleanup2 := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup2) tagAssociations := []sdk.TagAssociation{ { diff --git a/pkg/sdk/testint/system_functions_integration_test.go b/pkg/sdk/testint/system_functions_integration_test.go index 7ea71e9ef8..305a47ae42 100644 --- a/pkg/sdk/testint/system_functions_integration_test.go +++ b/pkg/sdk/testint/system_functions_integration_test.go @@ -13,14 +13,11 @@ func TestInt_GetTag(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - - tagTest, tagCleanup := createTag(t, client, testDb(t), schemaTest) + tagTest, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup) t.Run("masking policy tag", func(t *testing.T) { - maskingPolicyTest, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), schemaTest) + maskingPolicyTest, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(maskingPolicyCleanup) tagValue := random.String() @@ -41,7 +38,7 @@ func TestInt_GetTag(t *testing.T) { }) t.Run("masking policy with no set tag", func(t *testing.T) { - maskingPolicyTest, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), schemaTest) + maskingPolicyTest, maskingPolicyCleanup := createMaskingPolicy(t, client, testDb(t), testSchema(t)) t.Cleanup(maskingPolicyCleanup) s, err := client.SystemFunctions.GetTag(ctx, tagTest.ID(), maskingPolicyTest.ID(), sdk.ObjectTypeMaskingPolicy) diff --git a/pkg/sdk/testint/tasks_gen_integration_test.go b/pkg/sdk/testint/tasks_gen_integration_test.go index c586d024b6..beb0da02de 100644 --- a/pkg/sdk/testint/tasks_gen_integration_test.go +++ b/pkg/sdk/testint/tasks_gen_integration_test.go @@ -13,9 +13,6 @@ func TestInt_Tasks(t *testing.T) { client := testClient(t) ctx := testContext(t) - schema, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - sql := "SELECT CURRENT_TIMESTAMP" assertTask := func(t *testing.T, task *sdk.Task, id sdk.SchemaObjectIdentifier) { @@ -25,7 +22,7 @@ func TestInt_Tasks(t *testing.T) { assert.Equal(t, id.Name(), task.Name) assert.NotEmpty(t, task.Id) assert.Equal(t, testDb(t).Name, task.DatabaseName) - assert.Equal(t, schema.Name, task.SchemaName) + assert.Equal(t, testSchema(t).Name, task.SchemaName) assert.Equal(t, "ACCOUNTADMIN", task.Owner) assert.Equal(t, "", task.Comment) assert.Equal(t, "", task.Warehouse) @@ -50,7 +47,7 @@ func TestInt_Tasks(t *testing.T) { assert.Equal(t, id.Name(), task.Name) assert.NotEmpty(t, task.Id) assert.Equal(t, testDb(t).Name, task.DatabaseName) - assert.Equal(t, schema.Name, task.SchemaName) + assert.Equal(t, testSchema(t).Name, task.SchemaName) assert.Equal(t, "ACCOUNTADMIN", task.Owner) assert.Equal(t, comment, task.Comment) assert.Equal(t, warehouse, task.Warehouse) @@ -83,7 +80,7 @@ func TestInt_Tasks(t *testing.T) { assert.NotEmpty(t, task.CreatedOn) assert.Equal(t, id.Name(), task.Name) assert.Equal(t, testDb(t).Name, task.DatabaseName) - assert.Equal(t, schema.Name, task.SchemaName) + assert.Equal(t, testSchema(t).Name, task.SchemaName) assert.Equal(t, schedule, task.Schedule) // all below are not contained in the terse response, that's why all of them we expect to be empty @@ -114,7 +111,7 @@ func TestInt_Tasks(t *testing.T) { createTaskBasicRequest := func(t *testing.T) *sdk.CreateTaskRequest { t.Helper() name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) return sdk.NewCreateTaskRequest(id, sql) } @@ -181,7 +178,7 @@ func TestInt_Tasks(t *testing.T) { t.Run("create task: with after", func(t *testing.T) { otherName := random.String() - otherId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, otherName) + otherId := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, otherName) request := sdk.NewCreateTaskRequest(otherId, sql).WithSchedule(sdk.String("10 MINUTE")) @@ -216,7 +213,7 @@ func TestInt_Tasks(t *testing.T) { // }) t.Run("create task: with tags", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), schema) + tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup) request := createTaskBasicRequest(t). @@ -237,7 +234,7 @@ func TestInt_Tasks(t *testing.T) { sourceTask := createTask(t) name := random.String() - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, name) + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, name) request := sdk.NewCloneTaskRequest(id, sourceTask.ID()) @@ -266,7 +263,7 @@ func TestInt_Tasks(t *testing.T) { }) t.Run("drop task: non-existing", func(t *testing.T) { - id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, schema.Name, "does_not_exist") + id := sdk.NewSchemaObjectIdentifier(testDb(t).Name, testSchema(t).Name, "does_not_exist") err := client.Tasks.Drop(ctx, sdk.NewDropTaskRequest(id)) assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) @@ -296,7 +293,7 @@ func TestInt_Tasks(t *testing.T) { }) t.Run("alter task: set and unset tag", func(t *testing.T) { - tag, tagCleanup := createTag(t, client, testDb(t), schema) + tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup) task := createTask(t) @@ -453,7 +450,7 @@ func TestInt_Tasks(t *testing.T) { showRequest := sdk.NewShowTaskRequest(). WithLike(&sdk.Like{Pattern: &task1.Name}). - WithIn(&sdk.In{Schema: sdk.NewDatabaseObjectIdentifier(testDb(t).Name, schema.Name)}). + WithIn(&sdk.In{Schema: sdk.NewDatabaseObjectIdentifier(testDb(t).Name, testSchema(t).Name)}). WithLimit(&sdk.LimitFrom{Rows: sdk.Int(5)}) returnedTasks, err := client.Tasks.Show(ctx, showRequest) diff --git a/pkg/sdk/testint/users_integration_test.go b/pkg/sdk/testint/users_integration_test.go index 1c583a7563..444b9a7b55 100644 --- a/pkg/sdk/testint/users_integration_test.go +++ b/pkg/sdk/testint/users_integration_test.go @@ -80,10 +80,7 @@ func TestInt_UserCreate(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - - tag, tagCleanup := createTag(t, client, testDb(t), schemaTest) + tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup) t.Run("test complete case", func(t *testing.T) { diff --git a/pkg/sdk/testint/warehouses_integration_test.go b/pkg/sdk/testint/warehouses_integration_test.go index 958f6723b9..e852bdd909 100644 --- a/pkg/sdk/testint/warehouses_integration_test.go +++ b/pkg/sdk/testint/warehouses_integration_test.go @@ -54,11 +54,9 @@ func TestInt_WarehousesShow(t *testing.T) { func TestInt_WarehouseCreate(t *testing.T) { client := testClient(t) ctx := testContext(t) - schemaTest, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - tagTest, tagCleanup := createTag(t, client, testDb(t), schemaTest) + tagTest, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup) - tag2Test, tag2Cleanup := createTag(t, client, testDb(t), schemaTest) + tag2Test, tag2Cleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tag2Cleanup) t.Run("test complete", func(t *testing.T) { @@ -185,11 +183,9 @@ func TestInt_WarehouseAlter(t *testing.T) { client := testClient(t) ctx := testContext(t) - schema, schemaCleanup := createSchema(t, client, testDb(t)) - t.Cleanup(schemaCleanup) - tag, tagCleanup := createTag(t, client, testDb(t), schema) + tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup) - tag2, tagCleanup2 := createTag(t, client, testDb(t), schema) + tag2, tagCleanup2 := createTag(t, client, testDb(t), testSchema(t)) t.Cleanup(tagCleanup2) t.Run("terraform acc test", func(t *testing.T) {