mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
helper/schema: test real nil pointer to ResourceData.Set
This commit is contained in:
parent
c030148259
commit
58a8776c41
@ -143,9 +143,16 @@ func (d *ResourceData) Set(key string, value interface{}) error {
|
|||||||
// simplify the interface.
|
// simplify the interface.
|
||||||
reflectVal := reflect.ValueOf(value)
|
reflectVal := reflect.ValueOf(value)
|
||||||
if reflectVal.Kind() == reflect.Ptr {
|
if reflectVal.Kind() == reflect.Ptr {
|
||||||
reflectVal = reflect.Indirect(reflectVal)
|
if reflectVal.IsNil() {
|
||||||
if reflectVal.Kind() != reflect.Struct {
|
// If the pointer is nil, then the value is just nil
|
||||||
value = reflectVal.Interface()
|
value = nil
|
||||||
|
} else {
|
||||||
|
// Otherwise, we dereference the pointer as long as its not
|
||||||
|
// a pointer to a struct, since struct pointers are allowed.
|
||||||
|
reflectVal = reflect.Indirect(reflectVal)
|
||||||
|
if reflectVal.Kind() != reflect.Struct {
|
||||||
|
value = reflectVal.Interface()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1178,6 +1178,8 @@ func TestResourceDataHasChange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResourceDataSet(t *testing.T) {
|
func TestResourceDataSet(t *testing.T) {
|
||||||
|
var testNilPtr *string
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Schema map[string]*Schema
|
Schema map[string]*Schema
|
||||||
State *terraform.InstanceState
|
State *terraform.InstanceState
|
||||||
@ -1649,7 +1651,7 @@ func TestResourceDataSet(t *testing.T) {
|
|||||||
Diff: nil,
|
Diff: nil,
|
||||||
|
|
||||||
Key: "availability_zone",
|
Key: "availability_zone",
|
||||||
Value: nil,
|
Value: testNilPtr,
|
||||||
|
|
||||||
GetKey: "availability_zone",
|
GetKey: "availability_zone",
|
||||||
GetValue: "",
|
GetValue: "",
|
||||||
|
Loading…
Reference in New Issue
Block a user