test(analyser): enable slice ordering

main
sundowndev 2021-03-26 18:30:17 +01:00
parent 32daca00c4
commit 753dd50286
2 changed files with 29 additions and 21 deletions

View File

@ -83,28 +83,31 @@ func (a Analyzer) Analyze(remoteResources, resourcesFromState []resource.Resourc
analysis.AddManaged(stateRes)
delta, _ := diff.Diff(stateRes, remoteRes)
if len(delta) > 0 {
sort.Slice(delta, func(i, j int) bool {
return delta[i].Type < delta[j].Type
if len(delta) == 0 {
continue
}
sort.Slice(delta, func(i, j int) bool {
return delta[i].Type < delta[j].Type
})
changelog := make([]Change, 0, len(delta))
for _, change := range delta {
if filter.IsFieldIgnored(stateRes, change.Path) {
continue
}
c := Change{Change: change}
c.Computed = a.isComputedField(stateRes, c)
if c.Computed {
haveComputedDiff = true
}
changelog = append(changelog, c)
}
if len(changelog) > 0 {
analysis.AddDifference(Difference{
Res: stateRes,
Changelog: changelog,
})
changelog := make([]Change, 0, len(delta))
for _, change := range delta {
if filter.IsFieldIgnored(stateRes, change.Path) {
continue
}
c := Change{Change: change}
c.Computed = a.isComputedField(stateRes, c)
if c.Computed {
haveComputedDiff = true
}
changelog = append(changelog, c)
}
if len(changelog) > 0 {
analysis.AddDifference(Difference{
Res: stateRes,
Changelog: changelog,
})
}
}
}

View File

@ -975,6 +975,11 @@ func TestAnalyze(t *testing.T) {
t.Fatalf("Error creating new differ: %e", err)
}
differ, err := diff.NewDiffer(diff.SliceOrdering(true))
if err != nil {
t.Fatalf("Error creating new differ: %e", err)
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
filter := &mocks.Filter{}