core: Improve realism of map representation in testDiffFn
The diffs created by testDiffFn use the flatmap package directly, rather than running the diff-generation logic in helper/schema. It turns out that flatmap itself can generate the k+".#" keys used to indicate the length of a list, but only helper/schema itself knew how to generate the corresponding k+".%" keys used for maps. Rather than modifying the now-deprecated flatmap code directly (and risk breaking assumptions in shims elsewhere), here we just synthesize the extra required map element within the testDiffFn implementation, which then in turn allows the MockProvider diffFn shim to correctly recognize it as a map and convert it into a real cty.Map value to return.
This commit is contained in:
parent
bd6d3a638a
commit
5802953ab6
|
@ -8,6 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -357,6 +358,19 @@ func testFlatAttrDiffs(k string, i interface{}) map[string]*ResourceAttrDiff {
|
||||||
diffs[k] = attrDiff
|
diffs[k] = attrDiff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The legacy flatmap-based diff producing done by helper/schema would
|
||||||
|
// additionally insert a k+".%" key here recording the length of the map,
|
||||||
|
// which is for some reason not also done by flatmap.Flatten. To make our
|
||||||
|
// mock shims helper/schema-compatible, we'll just fake that up here.
|
||||||
|
switch t := i.(type) {
|
||||||
|
case map[string]interface{}:
|
||||||
|
attrDiff := &ResourceAttrDiff{
|
||||||
|
Old: "",
|
||||||
|
New: strconv.Itoa(len(t)),
|
||||||
|
}
|
||||||
|
diffs[k+".%"] = attrDiff
|
||||||
|
}
|
||||||
|
|
||||||
return diffs
|
return diffs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue