refactor: use new differ ordering

main
sundowndev 2021-03-22 11:17:50 +01:00
parent eba0839c6e
commit 286a07520c
No known key found for this signature in database
GPG Key ID: 8916203E540C65A4
2 changed files with 34 additions and 26 deletions

View File

@ -950,6 +950,12 @@ func TestAnalyze(t *testing.T) {
},
}
differ, err := diff.NewDiffer(diff.SliceOrdering(true))
if err != nil {
panic(err)
}
assert.NoError(t, err)
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
filter := &mocks.Filter{}
@ -980,7 +986,7 @@ func TestAnalyze(t *testing.T) {
t.Errorf("Drifted state does not match, got %t expected %t", result.IsSync(), !c.hasDrifted)
}
managedChanges, err := diff.Diff(result.Managed(), c.expected.Managed())
managedChanges, err := differ.Diff(result.Managed(), c.expected.Managed())
if err != nil {
t.Fatalf("Unable to compare %+v", err)
}
@ -990,33 +996,25 @@ func TestAnalyze(t *testing.T) {
}
}
for i, expected := range c.expected.Unmanaged() {
actual := result.Unmanaged()[i]
unmanagedChanges, err := diff.Diff(actual, expected)
unmanagedChanges, err := differ.Diff(result.Unmanaged(), c.expected.Unmanaged())
if err != nil {
t.Errorf("Unable to compare %+v", err)
t.Fatalf("Unable to compare %+v", err)
}
if len(unmanagedChanges) > 0 {
for _, change := range unmanagedChanges {
t.Errorf("%+v", change)
}
}
}
for i, expected := range c.expected.Deleted() {
actual := result.Deleted()[i]
deletedChanges, err := diff.Diff(actual, expected)
deletedChanges, err := differ.Diff(result.Deleted(), c.expected.Deleted())
if err != nil {
t.Errorf("Unable to compare %+v", err)
t.Fatalf("Unable to compare %+v", err)
}
if len(deletedChanges) > 0 {
for _, change := range deletedChanges {
t.Errorf("%+v", change)
}
}
}
diffChanges, err := diff.Diff(result.Differences(), c.expected.Differences())
if err != nil {
@ -1028,7 +1026,7 @@ func TestAnalyze(t *testing.T) {
}
}
summaryChanges, err := diff.Diff(c.expected.Summary(), result.Summary())
summaryChanges, err := differ.Diff(c.expected.Summary(), result.Summary())
if err != nil {
t.Fatalf("Unable to compare %+v", err)
}
@ -1038,7 +1036,7 @@ func TestAnalyze(t *testing.T) {
}
}
alertsChanges, err := diff.Diff(result.Alerts(), c.expected.Alerts())
alertsChanges, err := differ.Diff(result.Alerts(), c.expected.Alerts())
if err != nil {
t.Fatalf("Unable to compare %+v", err)
}

View File

@ -51,6 +51,16 @@ func IsSameResource(rRs, lRs Resource) bool {
}
func Sort(res []Resource) []Resource {
sort.SliceStable(res, func(i, j int) bool { return res[i].TerraformId() < res[j].TerraformId() })
sort.SliceStable(res, func(i, j int) bool {
if res[i].TerraformType() < res[j].TerraformType() {
return true
}
if res[i].TerraformType() > res[j].TerraformType() {
return false
}
return res[i].TerraformId() < res[j].TerraformId()
})
return res
}