-
Notifications
You must be signed in to change notification settings - Fork 9
/
list_acctest.go
47 lines (40 loc) · 1.44 KB
/
list_acctest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package sqlLogin
import (
"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"
)
func testListDataSource(testCtx *acctest.TestContext) {
var loginId string
defer testCtx.ExecMasterDB("DROP LOGIN [test_sql_login_list]")
testCtx.Test(resource.TestCase{
PreCheck: func() {
conn := testCtx.GetMasterDBConnection()
err := conn.QueryRow(`
CREATE LOGIN [test_sql_login_list] WITH PASSWORD='Str0ngPa$$w0rd124';
SELECT CONVERT(VARCHAR(85), [sid], 1) FROM sys.sql_logins WHERE [name]='test_sql_login_list'
`).Scan(&loginId)
testCtx.Require.NoError(err, "creating login")
},
Steps: []resource.TestStep{
{
Config: `data "mssql_sql_logins" "list" {}`,
Check: func(state *terraform.State) error {
expectedAttributes := map[string]string{
"id": loginId,
"name": "test_sql_login_list",
"must_change_password": "false",
"default_database_id": "1",
"default_language": "us_english",
"check_password_expiration": "false",
"check_password_policy": "true",
}
if testCtx.IsAzureTest {
expectedAttributes["check_password_policy"] = "false"
}
return resource.TestCheckTypeSetElemNestedAttrs("data.mssql_sql_logins.list", "logins.*", expectedAttributes)(state)
},
},
},
})
}