github.com/hashicorp/terraform-plugin-sdk@v1.17.2/terraform/transform_root_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform-plugin-sdk/internal/addrs"
     8  )
     9  
    10  func TestRootTransformer(t *testing.T) {
    11  	mod := testModule(t, "transform-root-basic")
    12  
    13  	g := Graph{Path: addrs.RootModuleInstance}
    14  	{
    15  		tf := &ConfigTransformer{Config: mod}
    16  		if err := tf.Transform(&g); err != nil {
    17  			t.Fatalf("err: %s", err)
    18  		}
    19  	}
    20  
    21  	{
    22  		transform := &MissingProviderTransformer{
    23  			Providers: []string{"aws", "do"},
    24  		}
    25  		if err := transform.Transform(&g); err != nil {
    26  			t.Fatalf("err: %s", err)
    27  		}
    28  	}
    29  
    30  	{
    31  		transform := &ProviderTransformer{}
    32  		if err := transform.Transform(&g); err != nil {
    33  			t.Fatalf("err: %s", err)
    34  		}
    35  	}
    36  
    37  	{
    38  		transform := &RootTransformer{}
    39  		if err := transform.Transform(&g); err != nil {
    40  			t.Fatalf("err: %s", err)
    41  		}
    42  	}
    43  
    44  	actual := strings.TrimSpace(g.String())
    45  	expected := strings.TrimSpace(testTransformRootBasicStr)
    46  	if actual != expected {
    47  		t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected)
    48  	}
    49  
    50  	root, err := g.Root()
    51  	if err != nil {
    52  		t.Fatalf("err: %s", err)
    53  	}
    54  	if _, ok := root.(graphNodeRoot); !ok {
    55  		t.Fatalf("bad: %#v", root)
    56  	}
    57  }
    58  
    59  const testTransformRootBasicStr = `
    60  aws_instance.foo
    61    provider.aws
    62  do_droplet.bar
    63    provider.do
    64  provider.aws
    65  provider.do
    66  root
    67    aws_instance.foo
    68    do_droplet.bar
    69  `