mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-04-26 06:02:09 -04:00
The tests did pass, but that was because they only tested part of the changes. By using the `schema.TestResourceDataRaw` function the schema and config are better tested and so they pointed out a problem with the schema of the Chef provisioner. The `Elem` fields did not have a `*schema.Schema` but a `schema.Schema` and in an `Elem` schema only the `Type` field may (and must) be set. Any other fields like `Optional` are not allowed here. Next to fixing that problem I also did a little refactoring and cleaning up. Mainly making the `ProvisionerS` private (`provisioner`) and removing the deprecated fields.
31 lines
629 B
Go
31 lines
629 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 {
|
|
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
|
|
}
|