Files
relspecgo/pkg/writers/template/template_data_test.go
T
warkanum 495a21b67b test: expand coverage across readers, writers, cmd, ui, diff and merge
Implements tests/_plans and previously deferred packages; updates plan
README with new coverage numbers.
2026-10-03 21:33:59 +02:00

87 lines
2.4 KiB
Go

package template
import (
"testing"
"git.warky.dev/wdevs/relspecgo/pkg/models"
)
func sampleDB() (*models.Database, *models.Schema, *models.Table) {
db := models.InitDatabase("shop")
schema := models.InitSchema("public")
table := models.InitTable("users", "public")
col := models.InitColumn("id", "users", "public")
col.Type = "integer"
col.IsPrimaryKey = true
table.Columns["id"] = col
schema.Tables = append(schema.Tables, table)
db.Schemas = append(db.Schemas, schema)
return db, schema, table
}
func TestTemplateDataConstructors(t *testing.T) {
db, schema, table := sampleDB()
meta := map[string]interface{}{"k": "v"}
dd := NewDatabaseData(db, meta)
if dd.Database != db || dd.ParentDatabase != db || dd.Summary == nil || len(dd.FlatColumns) != 1 || len(dd.FlatTables) != 1 || dd.Metadata["k"] != "v" {
t.Errorf("database data: %+v", dd)
}
if dd.Name() != "shop" {
t.Errorf("name: %q", dd.Name())
}
sd := NewSchemaData(schema, meta)
if sd.Schema != schema || sd.ParentDatabase == nil || sd.ParentDatabase.Name != "public" || len(sd.FlatColumns) != 1 {
t.Errorf("schema data: %+v", sd)
}
if sd.Name() != "public" {
t.Errorf("name: %q", sd.Name())
}
td := NewTableData(table, schema, db, meta)
if td.Table != table || td.ParentSchema != schema || td.ParentDatabase != db || td.Name() != "users" {
t.Errorf("table data: %+v", td)
}
dom := &models.Domain{Name: "billing"}
dmd := NewDomainData(dom, db, meta)
if dmd.Domain != dom || dmd.ParentDatabase != db || dmd.Name() != "billing" {
t.Errorf("domain data: %+v", dmd)
}
sc := &models.Script{Name: "seed"}
scd := NewScriptData(sc, schema, db, meta)
if scd.Script != sc || scd.ParentSchema != schema || scd.Name() != "seed" {
t.Errorf("script data: %+v", scd)
}
if got := (&TemplateData{}).Name(); got != "output" {
t.Errorf("empty name: %q", got)
}
}
func TestTypeMappersDelegate(t *testing.T) {
if got := SQLToGo("integer", false); got == "" {
t.Error("SQLToGo")
}
if got := SQLToTypeScript("integer", false); got == "" {
t.Error("SQLToTypeScript")
}
if got := SQLToJava("integer", false); got == "" {
t.Error("SQLToJava")
}
if got := SQLToPython("integer"); got == "" {
t.Error("SQLToPython")
}
if got := SQLToRust("integer", false); got == "" {
t.Error("SQLToRust")
}
if got := SQLToCSharp("integer", false); got == "" {
t.Error("SQLToCSharp")
}
if got := SQLToPhp("integer", false); got == "" {
t.Error("SQLToPhp")
}
}