terraform/config/module/tree_test.go

61 lines
1.1 KiB
Go
Raw Normal View History

2014-09-14 23:46:45 +02:00
package module
import (
"reflect"
2014-09-15 05:14:37 +02:00
"strings"
2014-09-14 23:46:45 +02:00
"testing"
)
func TestTree_Load(t *testing.T) {
2014-09-15 05:14:37 +02:00
storage := testStorage(t)
tree := NewTree(testConfig(t, "basic"))
2014-09-15 05:14:37 +02:00
// This should error because we haven't gotten things yet
if err := tree.Load(storage, GetModeNone); err == nil {
t.Fatal("should error")
}
// This should get things
if err := tree.Load(storage, GetModeGet); err != nil {
t.Fatalf("err: %s", err)
}
// This should no longer error
if err := tree.Load(storage, GetModeNone); err != nil {
t.Fatalf("err: %s", err)
}
2014-09-15 05:14:37 +02:00
actual := strings.TrimSpace(tree.String())
expected := strings.TrimSpace(treeLoadStr)
if actual != expected {
t.Fatalf("bad: \n\n%s", actual)
}
}
func TestTree_Modules(t *testing.T) {
2014-09-14 23:46:45 +02:00
tree := NewTree(testConfig(t, "basic"))
actual := tree.Modules()
expected := []*Module{
&Module{Name: "foo", Source: "./foo"},
}
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
2014-09-15 05:14:37 +02:00
func TestTree_Name(t *testing.T) {
tree := NewTree(testConfig(t, "basic"))
actual := tree.Name()
if actual != "<root>" {
t.Fatalf("bad: %#v", actual)
}
}
const treeLoadStr = `
<root>
foo
`