Skip to content

Commit 2ed3ca0

Browse files
test: added restrict_fk_on_non_standard_key for my cnf
Signed-off-by: Harshit Gangal <[email protected]>
1 parent 5aa3b11 commit 2ed3ca0

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Foreign key test configuration
2+
restrict_fk_on_non_standard_key = off

go/test/endtoend/vtgate/foreignkey/fk_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,3 +1504,14 @@ create table temp2(id bigint auto_increment primary key, col varchar(20) not nul
15041504
mcmp.Exec(`insert into temp1(col) values('a') `)
15051505
mcmp.ExecAllowAndCompareError(`insert into temp1(col) values('d') `, utils.CompareOptions{})
15061506
}
1507+
1508+
// TestRestrictFkOnNonStandardKey verifies that restrict_fk_on_non_standard_key is set to off
1509+
func TestRestrictFkOnNonStandardKey(t *testing.T) {
1510+
mcmp, closer := start(t)
1511+
defer closer()
1512+
1513+
// Check the setting on the MySQL side - this verifies that our extra_my.cnf is being applied
1514+
result := utils.Exec(t, mcmp.MySQLConn, `SHOW VARIABLES LIKE 'restrict_fk_on_non_standard_key'`)
1515+
require.Equal(t, 1, len(result.Rows), "Expected exactly one row for restrict_fk_on_non_standard_key variable")
1516+
require.Equal(t, "OFF", result.Rows[0][1].ToString(), "Expected restrict_fk_on_non_standard_key to be OFF")
1517+
}

go/test/endtoend/vtgate/foreignkey/main_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,18 @@ func TestMain(m *testing.M) {
101101
flag.Parse()
102102

103103
exitCode := func() int {
104+
// Setup EXTRA_MY_CNF for foreign key tests
105+
err := setupExtraMyConfig()
106+
if err != nil {
107+
fmt.Printf("Failed to setup extra MySQL config: %v\n", err)
108+
return 1
109+
}
110+
104111
clusterInstance = cluster.NewCluster(Cell, "localhost")
105112
defer clusterInstance.Teardown()
106113

107114
// Start topo server
108-
err := clusterInstance.StartTopo()
115+
err = clusterInstance.StartTopo()
109116
if err != nil {
110117
return 1
111118
}
@@ -232,3 +239,17 @@ func clearOutAllData(t testing.TB, vtConn *mysql.Conn, mysqlConn *mysql.Conn) {
232239
}
233240
}
234241
}
242+
243+
// setupExtraMyConfig sets the EXTRA_MY_CNF environment variable to point to our static config file
244+
func setupExtraMyConfig() error {
245+
// Get the absolute path to the config file in the same directory as this test
246+
configPath := "go/test/endtoend/vtgate/foreignkey/extra_my.cnf"
247+
248+
// Set the environment variable
249+
err := os.Setenv("EXTRA_MY_CNF", configPath)
250+
if err != nil {
251+
return fmt.Errorf("failed to set EXTRA_MY_CNF environment variable: %v", err)
252+
}
253+
254+
return nil
255+
}

0 commit comments

Comments
 (0)