Implements tests/_plans and previously deferred packages; updates plan README with new coverage numbers.
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package diff
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.warky.dev/wdevs/relspecgo/pkg/models"
|
|
)
|
|
|
|
func TestCompareSchemaDetails_DescriptionAndOwner(t *testing.T) {
|
|
mk := func(desc, owner string) *models.Schema {
|
|
s := models.InitSchema("public")
|
|
s.Description, s.Owner = desc, owner
|
|
return s
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
src, tgt *models.Schema
|
|
wantFields []string
|
|
}{
|
|
{"identical", mk("d", "o"), mk("d", "o"), nil},
|
|
{"description", mk("a", "o"), mk("b", "o"), []string{"description"}},
|
|
{"owner", mk("d", "x"), mk("d", "y"), []string{"owner"}},
|
|
{"both", mk("a", "x"), mk("b", "y"), []string{"description", "owner"}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := compareSchemaDetails(tt.src, tt.tgt)
|
|
if len(tt.wantFields) == 0 {
|
|
if got != nil {
|
|
t.Fatalf("expected no change, got %+v", got)
|
|
}
|
|
return
|
|
}
|
|
if got == nil || len(got.Changes) != len(tt.wantFields) {
|
|
t.Fatalf("changes: %+v", got)
|
|
}
|
|
for _, f := range tt.wantFields {
|
|
c, ok := got.Changes[f].(map[string]any)
|
|
if !ok {
|
|
t.Fatalf("missing %s: %+v", f, got.Changes)
|
|
}
|
|
if c["source"] == c["target"] {
|
|
t.Errorf("%s source and target equal: %v", f, c)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCompareDatabases_SchemaAttrsCounted(t *testing.T) {
|
|
src, tgt := models.InitDatabase("a"), models.InitDatabase("b")
|
|
s1, s2 := models.InitSchema("public"), models.InitSchema("public")
|
|
s1.Owner, s2.Owner = "alice", "bob"
|
|
src.Schemas, tgt.Schemas = append(src.Schemas, s1), append(tgt.Schemas, s2)
|
|
|
|
res := CompareDatabases(src, tgt)
|
|
if res.Schemas == nil || len(res.Schemas.Modified) != 1 {
|
|
t.Fatalf("schema owner change not reported: %+v", res.Schemas)
|
|
}
|
|
if ComputeSummary(res).Schemas.Modified != 1 {
|
|
t.Error("summary must count the modified schema")
|
|
}
|
|
}
|