Skip to content

Commit

Permalink
add use [db] to test collation verification methods
Browse files Browse the repository at this point in the history
  • Loading branch information
etinquis committed Sep 28, 2024
1 parent bc6dd16 commit 89e1591
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/services/database/resource_acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package database
import (
"database/sql"
"fmt"

"github.com/PGSSoft/terraform-provider-mssql/internal/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down Expand Up @@ -31,7 +32,12 @@ resource "mssql_database" %[1]q {
var checkCollation = func(dbName string, expected string) resource.TestCheckFunc {
return testCtx.SqlCheckMaster(func(db *sql.DB) error {
var collation string
err := db.QueryRow("SELECT collation_name FROM sys.databases WHERE name = @p1", dbName).Scan(&collation)
_, err := db.Exec(fmt.Sprintf("USE [%s]", dbName))
testCtx.Assert.NoError(err)
if err != nil {
return err
}
err = db.QueryRow("SELECT collation_name FROM sys.databases WHERE name = @p1", dbName).Scan(&collation)
testCtx.Assert.Equal(expected, collation)
return err
})
Expand All @@ -43,6 +49,8 @@ resource "mssql_database" %[1]q {
Config: newDatabaseResource("test", "new_db"),
Check: resource.ComposeTestCheckFunc(
testCtx.SqlCheckMaster(func(db *sql.DB) error {
_, err := db.Exec("USE [new_db]")
testCtx.Assert.NoError(err)
return db.QueryRow("SELECT database_id, collation_name FROM sys.databases WHERE name = 'new_db'").Scan(&dbId, &dbCollation)
}),
resource.ComposeAggregateTestCheckFunc(
Expand Down

0 comments on commit 89e1591

Please sign in to comment.