github.com/aspring/terraform@v0.8.2-0.20161216122603-6a8619a5db2e/terraform/transform_config_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/terraform/config/module"
     9  )
    10  
    11  func TestConfigTransformer_nilModule(t *testing.T) {
    12  	g := Graph{Path: RootModulePath}
    13  	tf := &ConfigTransformer{}
    14  	if err := tf.Transform(&g); err != nil {
    15  		t.Fatalf("err: %s", err)
    16  	}
    17  
    18  	if len(g.Vertices()) > 0 {
    19  		t.Fatalf("graph is not empty: %s", g.String())
    20  	}
    21  }
    22  
    23  func TestConfigTransformer_unloadedModule(t *testing.T) {
    24  	mod, err := module.NewTreeModule(
    25  		"", filepath.Join(fixtureDir, "graph-basic"))
    26  	if err != nil {
    27  		t.Fatalf("err: %s", err)
    28  	}
    29  
    30  	g := Graph{Path: RootModulePath}
    31  	tf := &ConfigTransformer{Module: mod}
    32  	if err := tf.Transform(&g); err == nil {
    33  		t.Fatal("should error")
    34  	}
    35  }
    36  
    37  func TestConfigTransformer(t *testing.T) {
    38  	g := Graph{Path: RootModulePath}
    39  	tf := &ConfigTransformer{Module: testModule(t, "graph-basic")}
    40  	if err := tf.Transform(&g); err != nil {
    41  		t.Fatalf("err: %s", err)
    42  	}
    43  
    44  	actual := strings.TrimSpace(g.String())
    45  	expected := strings.TrimSpace(testConfigTransformerGraphBasicStr)
    46  	if actual != expected {
    47  		t.Fatalf("bad:\n\n%s", actual)
    48  	}
    49  }
    50  
    51  const testConfigTransformerGraphBasicStr = `
    52  aws_instance.web
    53  aws_load_balancer.weblb
    54  aws_security_group.firewall
    55  openstack_floating_ip.random
    56  `