github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/transform_resource_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestResourceCountTransformer(t *testing.T) {
     9  	cfg := testModule(t, "transform-resource-count-basic").Config()
    10  	resource := cfg.Resources[0]
    11  
    12  	g := Graph{Path: RootModulePath}
    13  	{
    14  		tf := &ResourceCountTransformer{Resource: resource}
    15  		if err := tf.Transform(&g); err != nil {
    16  			t.Fatalf("err: %s", err)
    17  		}
    18  	}
    19  
    20  	actual := strings.TrimSpace(g.String())
    21  	expected := strings.TrimSpace(testResourceCountTransformStr)
    22  	if actual != expected {
    23  		t.Fatalf("bad:\n\n%s", actual)
    24  	}
    25  }
    26  
    27  func TestResourceCountTransformer_countNegative(t *testing.T) {
    28  	cfg := testModule(t, "transform-resource-count-negative").Config()
    29  	resource := cfg.Resources[0]
    30  
    31  	g := Graph{Path: RootModulePath}
    32  	{
    33  		tf := &ResourceCountTransformer{Resource: resource}
    34  		if err := tf.Transform(&g); err == nil {
    35  			t.Fatal("should error")
    36  		}
    37  	}
    38  }
    39  
    40  func TestResourceCountTransformer_deps(t *testing.T) {
    41  	cfg := testModule(t, "transform-resource-count-deps").Config()
    42  	resource := cfg.Resources[0]
    43  
    44  	g := Graph{Path: RootModulePath}
    45  	{
    46  		tf := &ResourceCountTransformer{Resource: resource}
    47  		if err := tf.Transform(&g); err != nil {
    48  			t.Fatalf("err: %s", err)
    49  		}
    50  	}
    51  
    52  	actual := strings.TrimSpace(g.String())
    53  	expected := strings.TrimSpace(testResourceCountTransformDepsStr)
    54  	if actual != expected {
    55  		t.Fatalf("bad:\n\n%s", actual)
    56  	}
    57  }
    58  
    59  const testResourceCountTransformStr = `
    60  aws_instance.foo #0
    61  aws_instance.foo #1
    62  aws_instance.foo #2
    63  `
    64  
    65  const testResourceCountTransformDepsStr = `
    66  aws_instance.foo #0
    67  aws_instance.foo #1
    68    aws_instance.foo #0
    69  `