core: Avoid crash on empty TypeSet blocks (#14305)
This commit is contained in:
parent
35fc047b69
commit
44a99e0ae5
|
@ -85,6 +85,9 @@ func SerializeValueForHash(buf *bytes.Buffer, val interface{}, schema *Schema) {
|
||||||
// to hash complex substructures when used in sets, and so the serialization
|
// to hash complex substructures when used in sets, and so the serialization
|
||||||
// is not reversible.
|
// is not reversible.
|
||||||
func SerializeResourceForHash(buf *bytes.Buffer, val interface{}, resource *Resource) {
|
func SerializeResourceForHash(buf *bytes.Buffer, val interface{}, resource *Resource) {
|
||||||
|
if val == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
sm := resource.Schema
|
sm := resource.Schema
|
||||||
m := val.(map[string]interface{})
|
m := val.(map[string]interface{})
|
||||||
var keys []string
|
var keys []string
|
||||||
|
|
|
@ -111,3 +111,20 @@ func TestSetUnion(t *testing.T) {
|
||||||
func testSetInt(v interface{}) int {
|
func testSetInt(v interface{}) int {
|
||||||
return v.(int)
|
return v.(int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHashResource_nil(t *testing.T) {
|
||||||
|
resource := &Resource{
|
||||||
|
Schema: map[string]*Schema{
|
||||||
|
"name": {
|
||||||
|
Type: TypeString,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
f := HashResource(resource)
|
||||||
|
|
||||||
|
idx := f(nil)
|
||||||
|
if idx != 0 {
|
||||||
|
t.Fatalf("Expected 0 when hashing nil, given: %d", idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue