Added test for walkDeps.
diff --git a/context_test.go b/context_test.go
index 1c4303b..8877be9 100644
--- a/context_test.go
+++ b/context_test.go
@@ -19,6 +19,10 @@
"testing"
)
+type Walker interface {
+ Walk() bool
+}
+
type fooModule struct {
properties struct {
Foo string
@@ -37,6 +41,10 @@
return f.properties.Foo
}
+func (f *fooModule) Walk() bool {
+ return true
+}
+
type barModule struct {
properties struct {
Bar bool
@@ -55,6 +63,10 @@
return b.properties.Bar
}
+func (b *barModule) Walk() bool {
+ return false
+}
+
func TestContextParse(t *testing.T) {
ctx := NewContext()
ctx.RegisterModuleType("foo_module", newFooModule)
@@ -99,3 +111,30 @@
}
}
+
+// |---B===D - represents a non-walkable edge
+// A = represents a walkable edge
+// |===C---E===G
+// | | A should not be visited because it's the root node.
+// |===F===| B, D and E should not be walked.
+func TestWalkDeps(t *testing.T) {
+ ctx := NewContext()
+ ctx.RegisterModuleType("foo_module", newFooModule)
+ ctx.RegisterModuleType("bar_module", newBarModule)
+ ctx.ParseBlueprintsFiles("context_test_Blueprints")
+ ctx.ResolveDependencies(nil)
+
+ var output string
+ topModule := ctx.moduleGroups["A"].modules[0]
+ ctx.walkDeps(topModule,
+ func(module, parent Module) bool {
+ if module.(Walker).Walk() {
+ output += ctx.ModuleName(module)
+ return true
+ }
+ return false
+ })
+ if output != "CFG" {
+ t.Fatalf("unexpected walkDeps behaviour: %s\nshould be: CFG", output)
+ }
+}