Merge pull request #12242 from hashicorp/jbardin/state-mv-sort
missing default cases in sort from #12219
This commit is contained in:
commit
92d4809db3
|
@ -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