github.com/sylr/terraform@v0.11.12-beta1/helper/schema/testing.go (about)

     1  package schema
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/terraform/config"
     7  	"github.com/hashicorp/terraform/terraform"
     8  )
     9  
    10  // TestResourceDataRaw creates a ResourceData from a raw configuration map.
    11  func TestResourceDataRaw(
    12  	t *testing.T, schema map[string]*Schema, raw map[string]interface{}) *ResourceData {
    13  	t.Helper()
    14  
    15  	c, err := config.NewRawConfig(raw)
    16  	if err != nil {
    17  		t.Fatalf("err: %s", err)
    18  	}
    19  
    20  	sm := schemaMap(schema)
    21  	diff, err := sm.Diff(nil, terraform.NewResourceConfig(c), nil, nil)
    22  	if err != nil {
    23  		t.Fatalf("err: %s", err)
    24  	}
    25  
    26  	result, err := sm.Data(nil, diff)
    27  	if err != nil {
    28  		t.Fatalf("err: %s", err)
    29  	}
    30  
    31  	return result
    32  }