mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-01-18 17:01:00 -05:00
It's alive! CustomizeDiff logic now has been inserted into the diff process. The test_resource_with_custom_diff resource provides some basic testing and a reference implementation. There should now be plenty of test coverage for this feature via the tests added for ResourceDiff, and the basic test added to the schemaMap.Diff test, and the test resource, but more can be added to test any specific case that comes up otherwise.
33 lines
652 B
Go
33 lines
652 B
Go
package schema
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/config"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
// TestResourceDataRaw creates a ResourceData from a raw configuration map.
|
|
func TestResourceDataRaw(
|
|
t *testing.T, schema map[string]*Schema, raw map[string]interface{}) *ResourceData {
|
|
t.Helper()
|
|
|
|
c, err := config.NewRawConfig(raw)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
sm := schemaMap(schema)
|
|
diff, err := sm.Diff(nil, terraform.NewResourceConfig(c), nil, nil)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
result, err := sm.Data(nil, diff)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
return result
|
|
}
|