Skip to content

Commit

Permalink
Only use the dynamic variable on Vitess 22 and later
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink committed Dec 9, 2024
1 parent c84400f commit 935e5f6
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions go/test/endtoend/vtgate/vschema/vschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,21 @@ func TestMain(m *testing.M) {
}

// List of users authorized to execute vschema ddl operations
timeNow := time.Now().Unix()
configFile = path.Join(os.TempDir(), fmt.Sprintf("vtgate-config-%d.json", timeNow))
err := writeConfig(configFile, map[string]string{
"vschema_ddl_authorized_users": "%",
})
if err != nil {
return 1, err
if utils.BinaryIsAtLeastAtVersion(22, "vtgate") {
timeNow := time.Now().Unix()
configFile = path.Join(os.TempDir(), fmt.Sprintf("vtgate-config-%d.json", timeNow))
err := writeConfig(configFile, map[string]string{
"vschema_ddl_authorized_users": "%",
})
if err != nil {
return 1, err
}
defer os.Remove(configFile)

clusterInstance.VtGateExtraArgs = []string{fmt.Sprintf("--config-file=%s", configFile), "--schema_change_signal=false"}
} else {
clusterInstance.VtGateExtraArgs = []string{"--vschema_ddl_authorized_users=%", "--schema_change_signal=false"}
}
defer os.Remove(configFile)

clusterInstance.VtGateExtraArgs = []string{fmt.Sprintf("--config-file=%s", configFile), "--schema_change_signal=false"}

// Start keyspace
keyspace := &cluster.Keyspace{
Expand Down Expand Up @@ -160,13 +164,15 @@ func TestVSchema(t *testing.T) {

utils.AssertMatches(t, conn, "delete from vt_user", `[]`)

writeConfig(configFile, map[string]string{
"vschema_ddl_authorized_users": "",
})
if utils.BinaryIsAtLeastAtVersion(22, "vtgate") {
writeConfig(configFile, map[string]string{
"vschema_ddl_authorized_users": "",
})

require.EventuallyWithT(t, func(t *assert.CollectT) {
_, err = conn.ExecuteFetch("ALTER VSCHEMA DROP TABLE main", 1000, false)
assert.Error(t, err)
assert.ErrorContains(t, err, "is not authorized to perform vschema operations")
}, 5*time.Second, 100*time.Millisecond)
require.EventuallyWithT(t, func(t *assert.CollectT) {
_, err = conn.ExecuteFetch("ALTER VSCHEMA DROP TABLE main", 1000, false)
assert.Error(t, err)
assert.ErrorContains(t, err, "is not authorized to perform vschema operations")
}, 5*time.Second, 100*time.Millisecond)
}
}

0 comments on commit 935e5f6

Please sign in to comment.