File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,6 +48,32 @@ func (g *Graph) Edges() []Edge {
4848 return result
4949}
5050
51+ // EdgesFrom returns the list of edges from the given source.
52+ func (g * Graph ) EdgesFrom (v Vertex ) []Edge {
53+ var result []Edge
54+ from := hashcode (v )
55+ for _ , e := range g .Edges () {
56+ if hashcode (e .Source ()) == from {
57+ result = append (result , e )
58+ }
59+ }
60+
61+ return result
62+ }
63+
64+ // EdgesTo returns the list of edges to the given target.
65+ func (g * Graph ) EdgesTo (v Vertex ) []Edge {
66+ var result []Edge
67+ search := hashcode (v )
68+ for _ , e := range g .Edges () {
69+ if hashcode (e .Target ()) == search {
70+ result = append (result , e )
71+ }
72+ }
73+
74+ return result
75+ }
76+
5177// HasVertex checks if the given Vertex is present in the graph.
5278func (g * Graph ) HasVertex (v Vertex ) bool {
5379 return g .vertices .Include (v )
Original file line number Diff line number Diff line change @@ -50,7 +50,8 @@ func (t *CBDEdgeTransformer) Transform(g *Graph) error {
5050 }
5151
5252 // Find the destroy edge. There should only be one.
53- for _ , e := range g .DownEdges (v ).List () {
53+ for _ , e := range g .EdgesTo (v ) {
54+ log .Printf ("WHAT: %#v" , e )
5455 // Not a destroy edge, ignore it
5556 de , ok := e .(* DestroyEdge )
5657 if ! ok {
Original file line number Diff line number Diff line change 77
88func TestCBDEdgeTransformer (t * testing.T ) {
99 g := Graph {Path : RootModulePath }
10- g .Add (& graphNodeDestroyerTest {AddrString : "test.A" })
10+ g .Add (& graphNodeCreatorTest {AddrString : "test.A" })
11+ g .Add (& graphNodeDestroyerTest {AddrString : "test.A" , CBD : true })
1112 g .Add (& graphNodeDestroyerTest {AddrString : "test.B" })
1213
1314 {
@@ -34,7 +35,9 @@ func TestCBDEdgeTransformer(t *testing.T) {
3435}
3536
3637const testTransformCBDEdgeBasicStr = `
38+ test.A
3739test.A (destroy)
40+ test.A
3841 test.B (destroy)
3942test.B (destroy)
4043`
You can’t perform that action at this time.
0 commit comments