fix: contain generated files and assets and harden SQL rendering

This commit is contained in:
2026-10-12 20:59:46 +02:00
parent 2fa48335d3
commit dd97413b8e
68 changed files with 2328 additions and 798 deletions
+23 -7
View File
@@ -9,13 +9,6 @@ import (
"git.warky.dev/wdevs/relspecgo/pkg/writers"
)
func TestStripComments(t *testing.T) {
got := stripComments("-- header\nCREATE TABLE `users` (\n `id` INT\n);")
if strings.HasPrefix(got, "--") || !strings.HasPrefix(got, "CREATE TABLE") {
t.Fatalf("stripComments() = %q", got)
}
}
func TestWriterGeneratesMySQLDDL(t *testing.T) {
db := models.InitDatabase("app")
s := models.InitSchema("app")
@@ -42,3 +35,26 @@ func TestWriterGeneratesMySQLDDL(t *testing.T) {
}
}
}
func TestDatabaseStatementsKeepEmbeddedDelimiters(t *testing.T) {
db := models.InitDatabase("app")
s := models.InitSchema("app")
db.Schemas = append(db.Schemas, s)
for _, name := range []string{"one", "two"} {
table := models.InitTable(name, s.Name)
col := models.InitColumn("text", name, s.Name)
col.Type = "text"
col.Default = "first;\n-- data, not a comment\nlast"
table.Columns[col.Name] = col
s.Tables = append(s.Tables, table)
}
statements := databaseStatements(db)
if len(statements) != 2 {
t.Fatalf("got %d statements", len(statements))
}
for _, stmt := range statements {
if !strings.Contains(stmt, "first;\n-- data, not a comment\nlast") {
t.Fatalf("default corrupted: %s", stmt)
}
}
}