Skip to content

Commit 0178325

Browse files
committed
Add proper skip logic to all testcontainers tests
- Add skip logic to match original tests for version-specific features - TestAccUser tests: skip MariaDB, TiDB, RDS, MySQL < 8.0.14 as appropriate - TestAccDefaultRoles: skip MySQL < 8.0, MariaDB, TiDB - TestAccRole: skip RDS, MySQL < 8.0 - TestAccGrant tests: skip RDS, TiDB, MariaDB, MySQL < 8.0 as appropriate - TestAccGlobalVar tests: skip MariaDB, TiDB, RDS as appropriate - All skip logic now matches the original test files
1 parent efa02d2 commit 0178325

5 files changed

+101
-18
lines changed

mysql/resource_default_roles_testcontainers_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ import (
1313
// TestAccDefaultRoles_basic_WithTestcontainers tests the mysql_default_roles resource
1414
// using Testcontainers instead of Makefile + Docker
1515
// Uses shared container set up in TestMain (MySQL 8.0 required for default roles)
16+
// Skips MySQL < 8.0, MariaDB, TiDB (same as original test)
1617
func TestAccDefaultRoles_basic_WithTestcontainers(t *testing.T) {
1718
// Use shared container set up in TestMain
1819
_ = getSharedMySQLContainer(t, "")
1920

2021
resource.Test(t, resource.TestCase{
21-
PreCheck: func() { testAccPreCheck(t) },
22+
PreCheck: func() {
23+
testAccPreCheck(t)
24+
testAccPreCheckSkipNotMySQL8(t)
25+
testAccPreCheckSkipMariaDB(t)
26+
testAccPreCheckSkipTiDB(t)
27+
},
2228
ProviderFactories: testAccProviderFactories,
2329
CheckDestroy: testAccDefaultRolesCheckDestroy,
2430
Steps: []resource.TestStep{

mysql/resource_global_variable_testcontainers_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
// TestAccGlobalVar_basic_WithTestcontainers tests the mysql_global_variable resource
1313
// Requires MySQL (not MariaDB/RDS)
1414
// Uses shared container set up in TestMain
15+
// Skips MariaDB, RDS (same as original test)
1516
func TestAccGlobalVar_basic_WithTestcontainers(t *testing.T) {
1617
// Use shared container set up in TestMain
1718
_ = getSharedMySQLContainer(t, "")
@@ -21,7 +22,7 @@ func TestAccGlobalVar_basic_WithTestcontainers(t *testing.T) {
2122
varValue := "1"
2223

2324
resource.Test(t, resource.TestCase{
24-
PreCheck: func() { testAccPreCheck(t) },
25+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckSkipMariaDB(t); testAccPreCheckSkipRds(t) },
2526
ProviderFactories: testAccProviderFactories,
2627
CheckDestroy: testAccGlobalVarCheckDestroy(varName, varValue),
2728
Steps: []resource.TestStep{
@@ -37,8 +38,9 @@ func TestAccGlobalVar_basic_WithTestcontainers(t *testing.T) {
3738
}
3839

3940
// TestAccGlobalVar_parseBoolean_WithTestcontainers tests boolean parsing
40-
// Requires MySQL (not MariaDB/RDS)
41+
// Requires MySQL (not MariaDB/TiDB/RDS)
4142
// Uses shared container set up in TestMain
43+
// Skips MariaDB, TiDB, RDS (same as original test)
4244
func TestAccGlobalVar_parseBoolean_WithTestcontainers(t *testing.T) {
4345
// Use shared container set up in TestMain
4446
_ = getSharedMySQLContainer(t, "")
@@ -48,7 +50,12 @@ func TestAccGlobalVar_parseBoolean_WithTestcontainers(t *testing.T) {
4850
varValue := "OFF"
4951

5052
resource.Test(t, resource.TestCase{
51-
PreCheck: func() { testAccPreCheck(t) },
53+
PreCheck: func() {
54+
testAccPreCheck(t)
55+
testAccPreCheckSkipMariaDB(t)
56+
testAccPreCheckSkipNotTiDB(t)
57+
testAccPreCheckSkipRds(t)
58+
},
5259
ProviderFactories: testAccProviderFactories,
5360
CheckDestroy: testAccGlobalVarCheckDestroy(varName, varValue),
5461
Steps: []resource.TestStep{

mysql/resource_grant_testcontainers_test.go

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import (
1414

1515
// TestAccGrant_WithTestcontainers tests basic grant functionality
1616
// Uses shared container set up in TestMain
17+
// Skips RDS (same as original test)
1718
func TestAccGrant_WithTestcontainers(t *testing.T) {
1819
// Use shared container set up in TestMain
1920
_ = getSharedMySQLContainer(t, "")
2021

2122
dbName := fmt.Sprintf("tf-test-%d", rand.Intn(100))
2223
userName := fmt.Sprintf("jdoe-%s", dbName)
2324
resource.Test(t, resource.TestCase{
24-
PreCheck: func() { testAccPreCheck(t) },
25+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckSkipRds(t) },
2526
ProviderFactories: testAccProviderFactories,
2627
CheckDestroy: testAccGrantCheckDestroy,
2728
Steps: []resource.TestStep{
@@ -56,14 +57,15 @@ func TestAccGrant_WithTestcontainers(t *testing.T) {
5657
}
5758

5859
// TestAccRevokePrivRefresh_WithTestcontainers tests privilege revocation and refresh
60+
// Skips RDS (same as original test)
5961
func TestAccRevokePrivRefresh_WithTestcontainers(t *testing.T) {
6062
// Use shared container set up in TestMain
6163
_ = getSharedMySQLContainer(t, "")
6264

6365
dbName := fmt.Sprintf("tf-test-%d", rand.Intn(100))
6466

6567
resource.Test(t, resource.TestCase{
66-
PreCheck: func() { testAccPreCheck(t) },
68+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckSkipRds(t) },
6769
ProviderFactories: testAccProviderFactories,
6870
CheckDestroy: testAccGrantCheckDestroy,
6971
Steps: []resource.TestStep{
@@ -142,13 +144,17 @@ func TestAccBroken_WithTestcontainers(t *testing.T) {
142144
}
143145

144146
// TestAccDifferentHosts_WithTestcontainers tests grants with different hosts
147+
// Skips TiDB (same as original test)
145148
func TestAccDifferentHosts_WithTestcontainers(t *testing.T) {
146149
// Use shared container set up in TestMain
147150
_ = getSharedMySQLContainer(t, "")
148151

149152
dbName := fmt.Sprintf("tf-test-%d", rand.Intn(100))
150153
resource.Test(t, resource.TestCase{
151-
PreCheck: func() { testAccPreCheck(t) },
154+
PreCheck: func() {
155+
testAccPreCheck(t)
156+
testAccPreCheckSkipTiDB(t)
157+
},
152158
ProviderFactories: testAccProviderFactories,
153159
CheckDestroy: testAccGrantCheckDestroy,
154160
Steps: []resource.TestStep{
@@ -178,13 +184,18 @@ func TestAccDifferentHosts_WithTestcontainers(t *testing.T) {
178184
}
179185

180186
// TestAccGrantComplex_WithTestcontainers tests complex grant scenarios
187+
// Skips TiDB, RDS (same as original test)
181188
func TestAccGrantComplex_WithTestcontainers(t *testing.T) {
182189
// Use shared container set up in TestMain
183190
_ = getSharedMySQLContainer(t, "")
184191

185192
dbName := fmt.Sprintf("tf-test-%d", rand.Intn(100))
186193
resource.Test(t, resource.TestCase{
187-
PreCheck: func() { testAccPreCheck(t) },
194+
PreCheck: func() {
195+
testAccPreCheck(t)
196+
testAccPreCheckSkipTiDB(t)
197+
testAccPreCheckSkipRds(t)
198+
},
188199
ProviderFactories: testAccProviderFactories,
189200
CheckDestroy: testAccGrantCheckDestroy,
190201
Steps: []resource.TestStep{
@@ -249,13 +260,20 @@ func TestAccGrantComplex_WithTestcontainers(t *testing.T) {
249260
}
250261

251262
// TestAccGrantComplexMySQL8_WithTestcontainers tests MySQL 8.0 specific grants
263+
// Skips RDS, MariaDB, MySQL < 8.0, TiDB (same as original test)
252264
func TestAccGrantComplexMySQL8_WithTestcontainers(t *testing.T) {
253265
// Use shared container set up in TestMain
254266
_ = getSharedMySQLContainer(t, "")
255267

256268
dbName := fmt.Sprintf("tf-test-%d", rand.Intn(100))
257269
resource.Test(t, resource.TestCase{
258-
PreCheck: func() { testAccPreCheck(t) },
270+
PreCheck: func() {
271+
testAccPreCheck(t)
272+
testAccPreCheckSkipRds(t)
273+
testAccPreCheckSkipMariaDB(t)
274+
testAccPreCheckSkipNotMySQLVersionMin(t, "8.0.0")
275+
testAccPreCheckSkipTiDB(t)
276+
},
259277
ProviderFactories: testAccProviderFactories,
260278
CheckDestroy: testAccGrantCheckDestroy,
261279
Steps: []resource.TestStep{
@@ -275,14 +293,19 @@ func TestAccGrantComplexMySQL8_WithTestcontainers(t *testing.T) {
275293
}
276294

277295
// TestAccGrant_role_WithTestcontainers tests role grants (requires MySQL 8.0+)
296+
// Skips RDS, MySQL < 8.0 (same as original test)
278297
func TestAccGrant_role_WithTestcontainers(t *testing.T) {
279298
// Use shared container set up in TestMain
280299
_ = getSharedMySQLContainer(t, "")
281300

282301
dbName := fmt.Sprintf("tf-test-%d", rand.Intn(100))
283302
roleName := fmt.Sprintf("TFRole-exp%d", rand.Intn(100))
284303
resource.Test(t, resource.TestCase{
285-
PreCheck: func() { testAccPreCheck(t) },
304+
PreCheck: func() {
305+
testAccPreCheck(t)
306+
testAccPreCheckSkipRds(t)
307+
testAccPreCheckSkipNotMySQLVersionMin(t, "8.0.0")
308+
},
286309
ProviderFactories: testAccProviderFactories,
287310
CheckDestroy: testAccGrantCheckDestroy,
288311
Steps: []resource.TestStep{
@@ -310,14 +333,20 @@ func TestAccGrant_role_WithTestcontainers(t *testing.T) {
310333
}
311334

312335
// TestAccGrant_roleToUser_WithTestcontainers tests granting roles to users (requires MySQL 8.0+)
336+
// Skips RDS, MySQL < 8.0, TiDB (same as original test)
313337
func TestAccGrant_roleToUser_WithTestcontainers(t *testing.T) {
314338
// Use shared container set up in TestMain
315339
_ = getSharedMySQLContainer(t, "")
316340

317341
dbName := fmt.Sprintf("tf-test-%d", rand.Intn(100))
318342
roleName := fmt.Sprintf("TFRole-%d", rand.Intn(100))
319343
resource.Test(t, resource.TestCase{
320-
PreCheck: func() { testAccPreCheck(t) },
344+
PreCheck: func() {
345+
testAccPreCheck(t)
346+
testAccPreCheckSkipRds(t)
347+
testAccPreCheckSkipNotMySQLVersionMin(t, "8.0.0")
348+
testAccPreCheckSkipTiDB(t)
349+
},
321350
ProviderFactories: testAccProviderFactories,
322351
CheckDestroy: testAccGrantCheckDestroy,
323352
Steps: []resource.TestStep{
@@ -334,13 +363,19 @@ func TestAccGrant_roleToUser_WithTestcontainers(t *testing.T) {
334363
}
335364

336365
// TestAccGrant_complexRoleGrants_WithTestcontainers tests complex role grant scenarios (requires MySQL 8.0+)
366+
// Skips MariaDB, MySQL < 8.0, TiDB (same as original test)
337367
func TestAccGrant_complexRoleGrants_WithTestcontainers(t *testing.T) {
338368
// Use shared container set up in TestMain
339369
_ = getSharedMySQLContainer(t, "")
340370

341371
dbName := fmt.Sprintf("tf-test-%d", rand.Intn(100))
342372
resource.Test(t, resource.TestCase{
343-
PreCheck: func() { testAccPreCheck(t) },
373+
PreCheck: func() {
374+
testAccPreCheck(t)
375+
testAccPreCheckSkipMariaDB(t)
376+
testAccPreCheckSkipNotMySQLVersionMin(t, "8.0.0")
377+
testAccPreCheckSkipTiDB(t)
378+
},
344379
ProviderFactories: testAccProviderFactories,
345380
CheckDestroy: testAccGrantCheckDestroy,
346381
Steps: []resource.TestStep{

mysql/resource_role_testcontainers_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
package mysql
55

66
import (
7+
"context"
78
"testing"
89

10+
"github.com/hashicorp/go-version"
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1012
)
1113

1214
// TestAccRole_basic_WithTestcontainers tests the mysql_role resource
1315
// using Testcontainers instead of Makefile + Docker
1416
// Uses shared container set up in TestMain (MySQL 8.0 required for roles)
17+
// Skips RDS and MySQL < 8.0 (same as original test)
1518
func TestAccRole_basic_WithTestcontainers(t *testing.T) {
1619
// Use shared container set up in TestMain
1720
_ = getSharedMySQLContainer(t, "")
@@ -20,7 +23,26 @@ func TestAccRole_basic_WithTestcontainers(t *testing.T) {
2023
resourceName := "mysql_role.test"
2124

2225
resource.Test(t, resource.TestCase{
23-
PreCheck: func() { testAccPreCheck(t) },
26+
PreCheck: func() {
27+
testAccPreCheck(t)
28+
testAccPreCheckSkipRds(t)
29+
// Check MySQL version (roles require 8.0+)
30+
ctx := context.Background()
31+
db, err := connectToMySQL(ctx, testAccProvider.Meta().(*MySQLConfiguration))
32+
if err != nil {
33+
return
34+
}
35+
36+
requiredVersion, _ := version.NewVersion("8.0.0")
37+
currentVersion, err := serverVersion(db)
38+
if err != nil {
39+
return
40+
}
41+
42+
if currentVersion.LessThan(requiredVersion) {
43+
t.Skip("Roles require MySQL 8+")
44+
}
45+
},
2446
ProviderFactories: testAccProviderFactories,
2547
CheckDestroy: testAccRoleCheckDestroy(roleName),
2648
Steps: []resource.TestStep{

mysql/resource_user_testcontainers_test.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
// TestAccUser_basic_WithTestcontainers tests the mysql_user resource
1515
// using Testcontainers instead of Makefile + Docker
1616
// Uses shared container set up in TestMain
17+
// Skips MariaDB (same as original test)
1718
func TestAccUser_basic_WithTestcontainers(t *testing.T) {
1819
// Use shared container set up in TestMain
1920
_ = getSharedMySQLContainer(t, "")
2021

2122
resource.Test(t, resource.TestCase{
22-
PreCheck: func() { testAccPreCheck(t) },
23+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckSkipMariaDB(t) },
2324
ProviderFactories: testAccProviderFactories,
2425
CheckDestroy: testAccUserCheckDestroy,
2526
Steps: []resource.TestStep{
@@ -67,7 +68,9 @@ func TestAccUser_auth_WithTestcontainers(t *testing.T) {
6768

6869
resource.Test(t, resource.TestCase{
6970
PreCheck: func() {
70-
testAccPreCheck(t)
71+
testAccPreCheckSkipTiDB(t)
72+
testAccPreCheckSkipMariaDB(t)
73+
testAccPreCheckSkipRds(t)
7174
// Check if mysql_no_login plugin is available
7275
ctx := context.Background()
7376
db, err := connectToMySQL(ctx, testAccProvider.Meta().(*MySQLConfiguration))
@@ -125,7 +128,12 @@ func TestAccUser_authConnect_WithTestcontainers(t *testing.T) {
125128
_ = getSharedMySQLContainer(t, "")
126129

127130
resource.Test(t, resource.TestCase{
128-
PreCheck: func() { testAccPreCheck(t) },
131+
PreCheck: func() {
132+
testAccPreCheck(t)
133+
testAccPreCheckSkipTiDB(t)
134+
testAccPreCheckSkipMariaDB(t)
135+
testAccPreCheckSkipRds(t)
136+
},
129137
ProviderFactories: testAccProviderFactories,
130138
CheckDestroy: testAccUserCheckDestroy,
131139
Steps: []resource.TestStep{
@@ -160,14 +168,19 @@ func TestAccUser_authConnect_WithTestcontainers(t *testing.T) {
160168
}
161169

162170
// TestAccUser_authConnectRetainOldPassword_WithTestcontainers tests retain_old_password
163-
// Requires MySQL 8.0.14+
171+
// Requires MySQL 8.0.14+ (not MariaDB/RDS)
164172
// Uses shared container set up in TestMain
165173
func TestAccUser_authConnectRetainOldPassword_WithTestcontainers(t *testing.T) {
166174
// Use shared container set up in TestMain
167175
_ = getSharedMySQLContainer(t, "")
168176

169177
resource.Test(t, resource.TestCase{
170-
PreCheck: func() { testAccPreCheck(t) },
178+
PreCheck: func() {
179+
testAccPreCheck(t)
180+
testAccPreCheckSkipMariaDB(t)
181+
testAccPreCheckSkipRds(t)
182+
testAccPreCheckSkipNotMySQLVersionMin(t, "8.0.14")
183+
},
171184
ProviderFactories: testAccProviderFactories,
172185
CheckDestroy: testAccUserCheckDestroy,
173186
Steps: []resource.TestStep{

0 commit comments

Comments
 (0)