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"
|
|
|
|
)
|
|
|
|
|
2014-09-15 01:17:29 +02:00
|
|
|
func TestTree_Load(t *testing.T) {
|
2014-09-15 05:14:37 +02:00
|
|
|
storage := testStorage(t)
|
2014-09-15 01:17:29 +02:00
|
|
|
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 {
|
2014-09-15 01:17:29 +02:00
|
|
|
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)
|
|
|
|
}
|
2014-09-15 01:17:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
`
|