Validates PostgreSQL table name (#19602)

This commit is contained in:
Ramon de Klein
2024-04-24 19:51:07 +02:00
committed by GitHub
parent df93ff92ba
commit 701da1282a
2 changed files with 62 additions and 0 deletions
+16
View File
@@ -36,3 +36,19 @@ func TestPostgreSQLRegistration(t *testing.T) {
t.Fatal("postgres driver not registered")
}
}
func TestPsqlTableNameValidation(t *testing.T) {
validTables := []string{"táblë", "table", "TableName", "\"Table name\"", "\"✅✅\"", "table$one", "\"táblë\""}
invalidTables := []string{"table name", "table \"name\"", "✅✅", "$table$"}
for _, name := range validTables {
if err := validatePsqlTableName(name); err != nil {
t.Errorf("Should be valid: %s - %s", name, err)
}
}
for _, name := range invalidTables {
if err := validatePsqlTableName(name); err != errInvalidPsqlTablename {
t.Errorf("Should be invalid: %s - %s", name, err)
}
}
}