Skip to content

Commit 647d624

Browse files
committed
Added a test case
1 parent a72f378 commit 647d624

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

mysql/resource_grant_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,3 +1246,63 @@ func TestDisallowDuplicateUsersSameTable(t *testing.T) {
12461246
},
12471247
})
12481248
}
1249+
1250+
func TestModifyPrivileges(t *testing.T) {
1251+
dbName := fmt.Sprintf("tf-test-%d", rand.Intn(100))
1252+
onePrivilege = "SELECT"
1253+
twoPrivileges := `"SELECT", "SHOW_ROUTINE"`
1254+
1255+
onePrivilegeConfig := getGrantsSampleWithPrivileges(dbName, onePrivilege)
1256+
twoPrivilegesConfig := getGrantsSampleWithPrivileges(dbName, twoPrivileges)
1257+
1258+
resource.Test(t, resource.TestCase{
1259+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckSkipRds(t) },
1260+
ProviderFactories: testAccProviderFactories,
1261+
CheckDestroy: testAccGrantCheckDestroy,
1262+
Steps: []resource.TestStep{
1263+
{
1264+
Config: testAccGrantConfigNoGrant(dbName),
1265+
Check: resource.ComposeTestCheckFunc(
1266+
prepareTable(dbName, "table1"),
1267+
),
1268+
},
1269+
{
1270+
Config: onePrivilegeConfig,
1271+
Check: resource.ComposeTestCheckFunc(
1272+
testAccPrivilege("mysql_grant.grant", "SELECT", true, false),
1273+
testAccPrivilege("mysql_grant.grant", "SHOW_ROUTINE", false, false),
1274+
),
1275+
},
1276+
{
1277+
Config: twoPrivilegesConfig,
1278+
RefreshState: true,
1279+
ExpectNonEmptyPlan: true,
1280+
Check: resource.ComposeTestCheckFunc(
1281+
testAccPrivilege("mysql_grant.grant", "SELECT", true, false),
1282+
testAccPrivilege("mysql_grant.grant", "SHOW_ROUTINE", true, false),
1283+
),
1284+
},
1285+
},
1286+
})
1287+
}
1288+
1289+
func getGrantsSampleWithPrivileges(dbName string, privileges string) string {
1290+
return fmt.Sprintf(`
1291+
resource "mysql_database" "test" {
1292+
name = "%s"
1293+
}
1294+
1295+
resource "mysql_user" "test" {
1296+
user = "jdoe-%s"
1297+
host = "example.com"
1298+
}
1299+
1300+
resource "mysql_grant" "grant" {
1301+
user = "${mysql_user.test.user}"
1302+
host = "${mysql_user.test.host}"
1303+
database = "${mysql_database.test.name}"
1304+
table = "table1"
1305+
privileges = [%s]
1306+
}
1307+
`, dbName, dbName, privileges)
1308+
}

0 commit comments

Comments
 (0)