1. pkg/models/models.go:184 - Fixed typo in ForeignKeyConstraint constant from "foreign_Key" to "foreign_key" 2. pkg/readers/drawdb/reader.go:62-68 - Fixed ReadSchema() to properly detect schema name from tables instead of hardcoding "default" 3. pkg/writers/dbml/writer.go:128 - Changed primary key attribute from "primary key" to DBML standard "pk" 4. pkg/writers/dbml/writer.go:208-221 - Fixed foreign key reference format to use "table.column" syntax for single columns instead of "table.(column)" Test Results All reader and writer tests are now passing: Readers: - DBML: 74.4% coverage (2 tests skipped due to missing parser features for Ref statements) - DCTX: 77.6% coverage - DrawDB: 83.6% coverage - JSON: 82.1% coverage - YAML: 82.1% coverage Writers: - Bun: 68.5% coverage - DBML: 91.5% coverage - DCTX: 100.0% coverage - DrawDB: 83.8% coverage - GORM: 69.2% coverage - JSON: 82.4% coverage - YAML: 82.4% coverage
111 lines
2.7 KiB
Go
111 lines
2.7 KiB
Go
package dctx
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.warky.dev/wdevs/relspecgo/pkg/models"
|
|
"git.warky.dev/wdevs/relspecgo/pkg/writers"
|
|
)
|
|
|
|
// TestWriter_WriteDatabase_ReturnsError tests that WriteDatabase returns an error
|
|
// since DCTX format is read-only
|
|
func TestWriter_WriteDatabase_ReturnsError(t *testing.T) {
|
|
db := models.InitDatabase("test_db")
|
|
schema := models.InitSchema("public")
|
|
table := models.InitTable("users", "public")
|
|
|
|
idCol := models.InitColumn("id", "users", "public")
|
|
idCol.Type = "bigint"
|
|
table.Columns["id"] = idCol
|
|
|
|
schema.Tables = append(schema.Tables, table)
|
|
db.Schemas = append(db.Schemas, schema)
|
|
|
|
opts := &writers.WriterOptions{
|
|
OutputPath: "/tmp/test.dctx",
|
|
}
|
|
|
|
writer := NewWriter(opts)
|
|
err := writer.WriteDatabase(db)
|
|
|
|
if err == nil {
|
|
t.Error("WriteDatabase() should return an error for read-only format")
|
|
}
|
|
|
|
if !strings.Contains(err.Error(), "read-only") {
|
|
t.Errorf("Error message should mention 'read-only', got: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestWriter_WriteSchema_ReturnsError tests that WriteSchema returns an error
|
|
// since DCTX format is read-only
|
|
func TestWriter_WriteSchema_ReturnsError(t *testing.T) {
|
|
schema := models.InitSchema("public")
|
|
table := models.InitTable("users", "public")
|
|
|
|
idCol := models.InitColumn("id", "users", "public")
|
|
idCol.Type = "bigint"
|
|
table.Columns["id"] = idCol
|
|
|
|
schema.Tables = append(schema.Tables, table)
|
|
|
|
opts := &writers.WriterOptions{
|
|
OutputPath: "/tmp/test.dctx",
|
|
}
|
|
|
|
writer := NewWriter(opts)
|
|
err := writer.WriteSchema(schema)
|
|
|
|
if err == nil {
|
|
t.Error("WriteSchema() should return an error for read-only format")
|
|
}
|
|
|
|
if !strings.Contains(err.Error(), "read-only") {
|
|
t.Errorf("Error message should mention 'read-only', got: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestWriter_WriteTable_ReturnsError tests that WriteTable returns an error
|
|
// since DCTX format is read-only
|
|
func TestWriter_WriteTable_ReturnsError(t *testing.T) {
|
|
table := models.InitTable("users", "public")
|
|
|
|
idCol := models.InitColumn("id", "users", "public")
|
|
idCol.Type = "bigint"
|
|
idCol.IsPrimaryKey = true
|
|
table.Columns["id"] = idCol
|
|
|
|
opts := &writers.WriterOptions{
|
|
OutputPath: "/tmp/test.dctx",
|
|
}
|
|
|
|
writer := NewWriter(opts)
|
|
err := writer.WriteTable(table)
|
|
|
|
if err == nil {
|
|
t.Error("WriteTable() should return an error for read-only format")
|
|
}
|
|
|
|
if !strings.Contains(err.Error(), "read-only") {
|
|
t.Errorf("Error message should mention 'read-only', got: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestNewWriter tests that NewWriter creates a valid writer instance
|
|
func TestNewWriter(t *testing.T) {
|
|
opts := &writers.WriterOptions{
|
|
OutputPath: "/tmp/test.dctx",
|
|
}
|
|
|
|
writer := NewWriter(opts)
|
|
|
|
if writer == nil {
|
|
t.Error("NewWriter() should return a non-nil writer")
|
|
}
|
|
|
|
if writer.options != opts {
|
|
t.Error("Writer options should match the provided options")
|
|
}
|
|
}
|