github.com/opentofu/opentofu@v1.7.1/internal/legacy/helper/schema/testing.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package schema
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/opentofu/opentofu/internal/legacy/tofu"
    12  )
    13  
    14  // TestResourceDataRaw creates a ResourceData from a raw configuration map.
    15  func TestResourceDataRaw(
    16  	t *testing.T, schema map[string]*Schema, raw map[string]interface{}) *ResourceData {
    17  	t.Helper()
    18  
    19  	c := tofu.NewResourceConfigRaw(raw)
    20  
    21  	sm := schemaMap(schema)
    22  	diff, err := sm.Diff(nil, c, nil, nil, true)
    23  	if err != nil {
    24  		t.Fatalf("err: %s", err)
    25  	}
    26  
    27  	result, err := sm.Data(nil, diff)
    28  	if err != nil {
    29  		t.Fatalf("err: %s", err)
    30  	}
    31  
    32  	return result
    33  }