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") } }