Merge pull request #12242 from hashicorp/jbardin/state-mv-sort

missing default cases in sort from #12219
This commit is contained in:
James Bardin 2017-02-27 08:57:39 -05:00 committed by GitHub
commit 92d4809db3
2 changed files with 36 additions and 1 deletions

View File

@ -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

View File

@ -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)
}
}