More Roundtrip tests
This commit is contained in:
@@ -445,3 +445,51 @@ func TestColumnProperties(t *testing.T) {
|
||||
t.Log("Note: No columns with default values found (this may be valid for the test data)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRelationships(t *testing.T) {
|
||||
opts := &readers.ReaderOptions{
|
||||
FilePath: filepath.Join("..", "..", "..", "examples", "dctx", "example.dctx"),
|
||||
}
|
||||
|
||||
reader := NewReader(opts)
|
||||
db, err := reader.ReadDatabase()
|
||||
if err != nil {
|
||||
t.Fatalf("ReadDatabase() error = %v", err)
|
||||
}
|
||||
|
||||
// Count total relationships across all tables
|
||||
relationshipCount := 0
|
||||
for _, schema := range db.Schemas {
|
||||
for _, table := range schema.Tables {
|
||||
relationshipCount += len(table.Relationships)
|
||||
}
|
||||
}
|
||||
|
||||
// The example.dctx file should have a significant number of relationships
|
||||
// With the fix for nested field GUID mapping, we expect around 100+ relationships
|
||||
if relationshipCount < 50 {
|
||||
t.Errorf("Expected at least 50 relationships, got %d. This may indicate relationships are not being parsed correctly", relationshipCount)
|
||||
}
|
||||
|
||||
t.Logf("Successfully parsed %d relationships", relationshipCount)
|
||||
|
||||
// Verify relationship properties
|
||||
for _, schema := range db.Schemas {
|
||||
for _, table := range schema.Tables {
|
||||
for _, rel := range table.Relationships {
|
||||
if rel.Name == "" {
|
||||
t.Errorf("Relationship in table '%s' should have a name", table.Name)
|
||||
}
|
||||
if rel.FromTable == "" {
|
||||
t.Errorf("Relationship '%s' should have a from table", rel.Name)
|
||||
}
|
||||
if rel.ToTable == "" {
|
||||
t.Errorf("Relationship '%s' should have a to table", rel.Name)
|
||||
}
|
||||
if rel.ForeignKey == "" {
|
||||
t.Errorf("Relationship '%s' should reference a foreign key", rel.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user