Skip to content

Commit

Permalink
chore: Set up schema once for integration tests (#2121)
Browse files Browse the repository at this point in the history
* Set up schema for integration tests

* Use test schema in pipes tests

* Use test schema in all other integration tests

* Remove use database and schema from masking policy test

* Do not use database nor schema

* Fix lint

* Use schema everywhere

* Add more logging for failing test

* Fix cleanup
  • Loading branch information
sfc-gh-asawicki committed Oct 18, 2023
1 parent 9858fea commit 5e3ebf4
Show file tree
Hide file tree
Showing 22 changed files with 234 additions and 349 deletions.
14 changes: 4 additions & 10 deletions pkg/sdk/testint/accounts_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down
63 changes: 24 additions & 39 deletions pkg/sdk/testint/alerts_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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),
}
Expand All @@ -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)

Expand All @@ -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),
Expand All @@ -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)
Expand All @@ -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),
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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)
})
Expand All @@ -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"

Expand All @@ -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)
Expand All @@ -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"

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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{
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
})
Expand Down
1 change: 1 addition & 0 deletions pkg/sdk/testint/context_functions_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pkg/sdk/testint/databases_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions pkg/sdk/testint/dynamic_table_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand All @@ -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),
}
Expand Down
Loading

0 comments on commit 5e3ebf4

Please sign in to comment.