missing defaults in sort
Need to properly catch some sort cases around 0-1 indexing. This can cause output to shift slightly, resulting in an intermittent test failure.
This commit is contained in:
parent
8ce8839397
commit
41ec5b3bd2
|
@ -2074,7 +2074,7 @@ func (r resourceNameSort) Less(i, j int) bool {
|
|||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return r[i] < r[j]
|
||||
}
|
||||
|
||||
// moduleStateSort implements sort.Interface to sort module states
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -1896,3 +1897,37 @@ func TestReadState_prune(t *testing.T) {
|
|||
t.Fatalf("got:\n%#v", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceNameSort(t *testing.T) {
|
||||
names := []string{
|
||||
"a",
|
||||
"b",
|
||||
"a.0",
|
||||
"a.c",
|
||||
"a.d",
|
||||
"c",
|
||||
"a.b.0",
|
||||
"a.b.1",
|
||||
"a.b.10",
|
||||
"a.b.2",
|
||||
}
|
||||
|
||||
sort.Sort(resourceNameSort(names))
|
||||
|
||||
expected := []string{
|
||||
"a",
|
||||
"a.0",
|
||||
"a.b.0",
|
||||
"a.b.1",
|
||||
"a.b.2",
|
||||
"a.b.10",
|
||||
"a.c",
|
||||
"a.d",
|
||||
"b",
|
||||
"c",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(names, expected) {
|
||||
t.Fatalf("got: %q\nexpected: %q\n", names, expected)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue