github.com/eliastor/durgaform@v0.0.0-20220816172711-d0ab2d17673e/internal/durgaform/graph_builder_test.go (about) 1 package durgaform 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/eliastor/durgaform/internal/addrs" 8 9 "github.com/eliastor/durgaform/internal/dag" 10 ) 11 12 func TestBasicGraphBuilder_impl(t *testing.T) { 13 var _ GraphBuilder = new(BasicGraphBuilder) 14 } 15 16 func TestBasicGraphBuilder(t *testing.T) { 17 b := &BasicGraphBuilder{ 18 Steps: []GraphTransformer{ 19 &testBasicGraphBuilderTransform{1}, 20 }, 21 } 22 23 g, err := b.Build(addrs.RootModuleInstance) 24 if err != nil { 25 t.Fatalf("err: %s", err) 26 } 27 28 if g.Path.String() != addrs.RootModuleInstance.String() { 29 t.Fatalf("wrong module path %q", g.Path) 30 } 31 32 actual := strings.TrimSpace(g.String()) 33 expected := strings.TrimSpace(testBasicGraphBuilderStr) 34 if actual != expected { 35 t.Fatalf("bad: %s", actual) 36 } 37 } 38 39 func TestBasicGraphBuilder_validate(t *testing.T) { 40 b := &BasicGraphBuilder{ 41 Steps: []GraphTransformer{ 42 &testBasicGraphBuilderTransform{1}, 43 &testBasicGraphBuilderTransform{2}, 44 }, 45 } 46 47 _, err := b.Build(addrs.RootModuleInstance) 48 if err == nil { 49 t.Fatal("should error") 50 } 51 } 52 53 type testBasicGraphBuilderTransform struct { 54 V dag.Vertex 55 } 56 57 func (t *testBasicGraphBuilderTransform) Transform(g *Graph) error { 58 g.Add(t.V) 59 return nil 60 } 61 62 const testBasicGraphBuilderStr = ` 63 1 64 `