mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-03-28 23:01:14 -04:00
Go 1.9 adds this new function which, when called, marks the caller as being a "helper function". Helper function stack frames are then skipped when trying to find a line of test code to blame for a test failure, so that the code in the main test function appears in the test failure output rather than a line within the helper function itself. This covers many -- but probaly not all -- of our test helpers across various packages.
33 lines
642 B
Go
33 lines
642 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))
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
result, err := sm.Data(nil, diff)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
return result
|
|
}
|