github.com/nicgrayson/terraform@v0.4.3-0.20150415203910-c4de50829380/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  const testResourceCountTransformStr = `
    41  aws_instance.foo #0
    42    aws_instance.foo #2
    43  aws_instance.foo #1
    44    aws_instance.foo #2
    45  aws_instance.foo #2
    46    aws_instance.foo #2
    47  `