Merge pull request #3573 from hashicorp/b-state-store-module-order-consistently
core: store deeply nested modules in a consistent order in the state
This commit is contained in:
commit
5b1c03879a
|
@ -1207,9 +1207,8 @@ func (s moduleStateSort) Less(i, j int) bool {
|
|||
return len(a.Path) < len(b.Path)
|
||||
}
|
||||
|
||||
// Otherwise, compare by last path element
|
||||
idx := len(a.Path) - 1
|
||||
return a.Path[idx] < b.Path[idx]
|
||||
// Otherwise, compare lexically
|
||||
return strings.Join(a.Path, ".") < strings.Join(b.Path, ".")
|
||||
}
|
||||
|
||||
func (s moduleStateSort) Swap(i, j int) {
|
||||
|
|
|
@ -40,6 +40,23 @@ func TestStateAddModule(t *testing.T) {
|
|||
[]string{"root", "foo", "bar"},
|
||||
},
|
||||
},
|
||||
// Same last element, different middle element
|
||||
{
|
||||
[][]string{
|
||||
[]string{"root", "foo", "bar"}, // This one should sort after...
|
||||
[]string{"root", "foo"},
|
||||
[]string{"root"},
|
||||
[]string{"root", "bar", "bar"}, // ...this one.
|
||||
[]string{"root", "bar"},
|
||||
},
|
||||
[][]string{
|
||||
[]string{"root"},
|
||||
[]string{"root", "bar"},
|
||||
[]string{"root", "foo"},
|
||||
[]string{"root", "bar", "bar"},
|
||||
[]string{"root", "foo", "bar"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
|
Loading…
Reference in New Issue