pgraph: Remove NewVertex and NewEdge methods and fix examples

Since the pgraph graph can store arbitrary pointers, we don't need a
special method to create the vertices or edges as long as they implement
the String() string method. This cleans up the library and some of the
examples which I let rot previously.
This commit is contained in:
James Shubin
2017-05-31 17:47:36 -04:00
parent 6838dd02c0
commit 0545c4167b
9 changed files with 139 additions and 161 deletions

View File

@@ -63,7 +63,7 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
if err != nil {
return nil, err
}
var vertex *pgraph.Vertex
var vertex pgraph.Vertex
for i := uint(0); i < obj.Count; i++ {
n := &resources.NoopRes{
BaseRes: resources.BaseRes{
@@ -71,12 +71,11 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
MetaParams: resources.DefaultMetaParams,
},
}
v := pgraph.NewVertex(n)
g.AddVertex(v)
g.AddVertex(n)
if i > 0 {
g.AddEdge(vertex, v, pgraph.NewEdge(fmt.Sprintf("e%d", i)))
g.AddEdge(vertex, n, &resources.Edge{Name: fmt.Sprintf("e%d", i)})
}
vertex = v // save
vertex = n // save
}
//g, err := config.NewGraphFromConfig(obj.data.Hostname, obj.data.World, obj.data.Noop)

View File

@@ -75,8 +75,7 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
State: "present",
}
v0 := pgraph.NewVertex(f0)
g.AddVertex(v0)
g.AddVertex(f0)
p1 := &resources.PasswordRes{
BaseRes: resources.BaseRes{
@@ -86,8 +85,7 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
Length: 8, // generated string will have this many characters
Saved: true, // this causes passwords to be stored in plain text!
}
v1 := pgraph.NewVertex(p1)
g.AddVertex(v1)
g.AddVertex(p1)
f1 := &resources.FileRes{
BaseRes: resources.BaseRes{
@@ -103,8 +101,7 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
State: "present",
}
v2 := pgraph.NewVertex(f1)
g.AddVertex(v2)
g.AddVertex(f1)
n1 := &resources.NoopRes{
BaseRes: resources.BaseRes{
@@ -113,18 +110,17 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
},
}
v3 := pgraph.NewVertex(n1)
g.AddVertex(v3)
g.AddVertex(n1)
e0 := pgraph.NewEdge("e0")
e0.Notify = true // send a notification from v0 to v1
g.AddEdge(v0, v1, e0)
e0 := &resources.Edge{Name: "e0"}
e0.Notify = true // send a notification from f0 to p1
g.AddEdge(f0, p1, e0)
g.AddEdge(v1, v2, pgraph.NewEdge("e1"))
g.AddEdge(p1, f1, &resources.Edge{Name: "e1"})
e2 := pgraph.NewEdge("e2")
e2.Notify = true // send a notification from v2 to v3
g.AddEdge(v2, v3, e2)
e2 := &resources.Edge{Name: "e2"}
e2.Notify = true // send a notification from f1 to n1
g.AddEdge(f1, n1, e2)
//g, err := config.NewGraphFromConfig(obj.data.Hostname, obj.data.World, obj.data.Noop)
return g, nil

View File

@@ -72,20 +72,6 @@ func NewGraph(name string) (*Graph, error) {
return g, nil
}
// NewVertex returns whatever was passed in. This is for compatibility with the
// usage of the old NewVertex method. This is considered deprecated.
// FIXME: remove me
func NewVertex(x Vertex) Vertex {
return x
}
// NewEdge returns whatever was passed in. This is for compatibility with the
// usage of the old NewEdge method. This is considered deprecated.
// FIXME: remove me
func NewEdge(x Edge) Edge {
return x
}
// Value returns a value stored alongside the graph in a particular key.
func (g *Graph) Value(key string) (interface{}, bool) {
val, exists := g.kv[key]

View File

@@ -35,8 +35,7 @@ func (v *vertex) String() string {
// NV is a helper function to make testing easier. It creates a new noop vertex.
func NV(s string) Vertex {
obj := &vertex{s}
return NewVertex(obj)
return &vertex{s}
}
// edge is a test struct to test the library.
@@ -51,8 +50,7 @@ func (e *edge) String() string {
// NE is a helper function to make testing easier. It creates a new noop edge.
func NE(s string) Edge {
obj := &edge{s}
return NewEdge(obj)
return &edge{s}
}
func TestPgraphT1(t *testing.T) {

View File

@@ -285,12 +285,12 @@ func TestPgraphGrouping1(t *testing.T) {
func TestPgraphGrouping2(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{ // grouping to limit variable scope
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a1 := NewNoopResTest("a1")
g1.AddVertex(a1)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a1 := NewNoopResTest("a1")
g2.AddVertex(a1)
}
runGraphCmp(t, g1, g2)
@@ -300,14 +300,14 @@ func TestPgraphGrouping2(t *testing.T) {
func TestPgraphGrouping3(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a1 := NewNoopResTest("a1")
b1 := NewNoopResTest("b1")
g1.AddVertex(a1, b1)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a1 := NewNoopResTest("a1")
b1 := NewNoopResTest("b1")
g2.AddVertex(a1, b1)
}
runGraphCmp(t, g1, g2)
@@ -317,13 +317,13 @@ func TestPgraphGrouping3(t *testing.T) {
func TestPgraphGrouping4(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
g1.AddVertex(a1, a2)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2"))
a := NewNoopResTest("a1,a2")
g2.AddVertex(a)
}
runGraphCmp(t, g1, g2)
@@ -333,14 +333,14 @@ func TestPgraphGrouping4(t *testing.T) {
func TestPgraphGrouping5(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
a3 := pgraph.NewVertex(NewNoopResTest("a3"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
a3 := NewNoopResTest("a3")
g1.AddVertex(a1, a2, a3)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2,a3"))
a := NewNoopResTest("a1,a2,a3")
g2.AddVertex(a)
}
runGraphCmp(t, g1, g2)
@@ -350,15 +350,15 @@ func TestPgraphGrouping5(t *testing.T) {
func TestPgraphGrouping6(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
b1 := NewNoopResTest("b1")
g1.AddVertex(a1, a2, b1)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a := NewNoopResTest("a1,a2")
b1 := NewNoopResTest("b1")
g2.AddVertex(a, b1)
}
runGraphCmp(t, g1, g2)
@@ -368,16 +368,16 @@ func TestPgraphGrouping6(t *testing.T) {
func TestPgraphGrouping7(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
a3 := pgraph.NewVertex(NewNoopResTest("a3"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
a3 := NewNoopResTest("a3")
b1 := NewNoopResTest("b1")
g1.AddVertex(a1, a2, a3, b1)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2,a3"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a := NewNoopResTest("a1,a2,a3")
b1 := NewNoopResTest("b1")
g2.AddVertex(a, b1)
}
runGraphCmp(t, g1, g2)
@@ -387,16 +387,16 @@ func TestPgraphGrouping7(t *testing.T) {
func TestPgraphGrouping8(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
b2 := pgraph.NewVertex(NewNoopResTest("b2"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
b1 := NewNoopResTest("b1")
b2 := NewNoopResTest("b2")
g1.AddVertex(a1, a2, b1, b2)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2"))
b := pgraph.NewVertex(NewNoopResTest("b1,b2"))
a := NewNoopResTest("a1,a2")
b := NewNoopResTest("b1,b2")
g2.AddVertex(a, b)
}
runGraphCmp(t, g1, g2)
@@ -406,17 +406,17 @@ func TestPgraphGrouping8(t *testing.T) {
func TestPgraphGrouping9(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
b2 := pgraph.NewVertex(NewNoopResTest("b2"))
b3 := pgraph.NewVertex(NewNoopResTest("b3"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
b1 := NewNoopResTest("b1")
b2 := NewNoopResTest("b2")
b3 := NewNoopResTest("b3")
g1.AddVertex(a1, a2, b1, b2, b3)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2"))
b := pgraph.NewVertex(NewNoopResTest("b1,b2,b3"))
a := NewNoopResTest("a1,a2")
b := NewNoopResTest("b1,b2,b3")
g2.AddVertex(a, b)
}
runGraphCmp(t, g1, g2)
@@ -426,16 +426,16 @@ func TestPgraphGrouping9(t *testing.T) {
func TestPgraphGrouping10(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a1 := NewNoopResTest("a1")
b1 := NewNoopResTest("b1")
c1 := NewNoopResTest("c1")
g1.AddVertex(a1, b1, c1)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a1 := NewNoopResTest("a1")
b1 := NewNoopResTest("b1")
c1 := NewNoopResTest("c1")
g2.AddVertex(a1, b1, c1)
}
runGraphCmp(t, g1, g2)
@@ -445,17 +445,17 @@ func TestPgraphGrouping10(t *testing.T) {
func TestPgraphGrouping11(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
b2 := pgraph.NewVertex(NewNoopResTest("b2"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a1 := NewNoopResTest("a1")
b1 := NewNoopResTest("b1")
b2 := NewNoopResTest("b2")
c1 := NewNoopResTest("c1")
g1.AddVertex(a1, b1, b2, c1)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b := pgraph.NewVertex(NewNoopResTest("b1,b2"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a1 := NewNoopResTest("a1")
b := NewNoopResTest("b1,b2")
c1 := NewNoopResTest("c1")
g2.AddVertex(a1, b, c1)
}
runGraphCmp(t, g1, g2)
@@ -468,9 +468,9 @@ func TestPgraphGrouping11(t *testing.T) {
func TestPgraphGrouping12(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
b1 := NewNoopResTest("b1")
e1 := NE("e1")
e2 := NE("e2")
g1.AddEdge(a1, b1, e1)
@@ -478,8 +478,8 @@ func TestPgraphGrouping12(t *testing.T) {
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a := NewNoopResTest("a1,a2")
b1 := NewNoopResTest("b1")
e := NE("e1,e2")
g2.AddEdge(a, b1, e)
}
@@ -493,9 +493,9 @@ func TestPgraphGrouping12(t *testing.T) {
func TestPgraphGrouping13(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
b1 := NewNoopResTest("b1")
e1 := NE("e1")
e2 := NE("e2")
g1.AddEdge(b1, a1, e1)
@@ -503,8 +503,8 @@ func TestPgraphGrouping13(t *testing.T) {
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a := NewNoopResTest("a1,a2")
b1 := NewNoopResTest("b1")
e := NE("e1,e2")
g2.AddEdge(b1, a, e)
}
@@ -518,10 +518,10 @@ func TestPgraphGrouping13(t *testing.T) {
func TestPgraphGrouping14(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
a3 := pgraph.NewVertex(NewNoopResTest("a3"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
a3 := NewNoopResTest("a3")
b1 := NewNoopResTest("b1")
e1 := NE("e1")
e2 := NE("e2")
e3 := NE("e3")
@@ -531,8 +531,8 @@ func TestPgraphGrouping14(t *testing.T) {
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2,a3"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
a := NewNoopResTest("a1,a2,a3")
b1 := NewNoopResTest("b1")
e := NE("e1,e2,e3")
g2.AddEdge(a, b1, e)
}
@@ -548,10 +548,10 @@ func TestPgraphGrouping14(t *testing.T) {
func TestPgraphGrouping15(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
b2 := pgraph.NewVertex(NewNoopResTest("b2"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a1 := NewNoopResTest("a1")
b1 := NewNoopResTest("b1")
b2 := NewNoopResTest("b2")
c1 := NewNoopResTest("c1")
e1 := NE("e1")
e2 := NE("e2")
e3 := NE("e3")
@@ -563,9 +563,9 @@ func TestPgraphGrouping15(t *testing.T) {
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b := pgraph.NewVertex(NewNoopResTest("b1,b2"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a1 := NewNoopResTest("a1")
b := NewNoopResTest("b1,b2")
c1 := NewNoopResTest("c1")
e1 := NE("e1,e2")
e2 := NE("e3,e4")
g2.AddEdge(a1, b, e1)
@@ -585,10 +585,10 @@ func TestPgraphGrouping15(t *testing.T) {
func TestPgraphGrouping16(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
b1 := NewNoopResTest("b1")
c1 := NewNoopResTest("c1")
e1 := NE("e1")
e2 := NE("e2")
e3 := NE("e3")
@@ -598,9 +598,9 @@ func TestPgraphGrouping16(t *testing.T) {
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a := NewNoopResTest("a1,a2")
b1 := NewNoopResTest("b1")
c1 := NewNoopResTest("c1")
e1 := NE("e1,e3")
e2 := NE("e2,e3") // e3 gets "merged through" to BOTH edges!
g2.AddEdge(a, b1, e1)
@@ -618,10 +618,10 @@ func TestPgraphGrouping16(t *testing.T) {
func TestPgraphGrouping17(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
b2 := pgraph.NewVertex(NewNoopResTest("b2"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a1 := NewNoopResTest("a1")
b1 := NewNoopResTest("b1")
b2 := NewNoopResTest("b2")
c1 := NewNoopResTest("c1")
e1 := NE("e1")
e2 := NE("e2")
e3 := NE("e3")
@@ -631,9 +631,9 @@ func TestPgraphGrouping17(t *testing.T) {
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b := pgraph.NewVertex(NewNoopResTest("b1,b2"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a1 := NewNoopResTest("a1")
b := NewNoopResTest("b1,b2")
c1 := NewNoopResTest("c1")
e1 := NE("e1")
e2 := NE("e2,e3")
g2.AddEdge(a1, b, e1)
@@ -652,11 +652,11 @@ func TestPgraphGrouping17(t *testing.T) {
func TestPgraphGrouping18(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
b1 := pgraph.NewVertex(NewNoopResTest("b1"))
b2 := pgraph.NewVertex(NewNoopResTest("b2"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
b1 := NewNoopResTest("b1")
b2 := NewNoopResTest("b2")
c1 := NewNoopResTest("c1")
e1 := NE("e1")
e2 := NE("e2")
e3 := NE("e3")
@@ -668,9 +668,9 @@ func TestPgraphGrouping18(t *testing.T) {
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a := pgraph.NewVertex(NewNoopResTest("a1,a2"))
b := pgraph.NewVertex(NewNoopResTest("b1,b2"))
c1 := pgraph.NewVertex(NewNoopResTest("c1"))
a := NewNoopResTest("a1,a2")
b := NewNoopResTest("b1,b2")
c1 := NewNoopResTest("c1")
e1 := NE("e1,e3")
e2 := NE("e2,e3,e4") // e3 gets "merged through" to BOTH edges!
g2.AddEdge(a, b, e1)
@@ -686,15 +686,15 @@ func TestPgraphGrouping18(t *testing.T) {
func TestPgraphGroupingConnected0(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
e1 := NE("e1")
g1.AddEdge(a1, a2, e1)
}
g2, _ := pgraph.NewGraph("g2") // expected result ?
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
a1 := NewNoopResTest("a1")
a2 := NewNoopResTest("a2")
e1 := NE("e1")
g2.AddEdge(a1, a2, e1)
}
@@ -710,9 +710,9 @@ func TestPgraphGroupingConnected0(t *testing.T) {
func TestPgraphGroupingConnected1(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b := pgraph.NewVertex(NewNoopResTest("b"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
a1 := NewNoopResTest("a1")
b := NewNoopResTest("b")
a2 := NewNoopResTest("a2")
e1 := NE("e1")
e2 := NE("e2")
g1.AddEdge(a1, b, e1)
@@ -720,9 +720,9 @@ func TestPgraphGroupingConnected1(t *testing.T) {
}
g2, _ := pgraph.NewGraph("g2") // expected result ?
{
a1 := pgraph.NewVertex(NewNoopResTest("a1"))
b := pgraph.NewVertex(NewNoopResTest("b"))
a2 := pgraph.NewVertex(NewNoopResTest("a2"))
a1 := NewNoopResTest("a1")
b := NewNoopResTest("b")
a2 := NewNoopResTest("a2")
e1 := NE("e1")
e2 := NE("e2")
g2.AddEdge(a1, b, e1)

View File

@@ -54,16 +54,16 @@ func NewNoopResTestSema(name string, semas []string) *NoopResTest {
func TestPgraphSemaphoreGrouping1(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTestSema("a1", []string{"s:1"}))
a2 := pgraph.NewVertex(NewNoopResTestSema("a2", []string{"s:2"}))
a3 := pgraph.NewVertex(NewNoopResTestSema("a3", []string{"s:3"}))
a1 := NewNoopResTestSema("a1", []string{"s:1"})
a2 := NewNoopResTestSema("a2", []string{"s:2"})
a3 := NewNoopResTestSema("a3", []string{"s:3"})
g1.AddVertex(a1)
g1.AddVertex(a2)
g1.AddVertex(a3)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a123 := pgraph.NewVertex(NewNoopResTestSema("a1,a2,a3", []string{"s:1", "s:2", "s:3"}))
a123 := NewNoopResTestSema("a1,a2,a3", []string{"s:1", "s:2", "s:3"})
g2.AddVertex(a123)
}
runGraphCmp(t, g1, g2)
@@ -72,16 +72,16 @@ func TestPgraphSemaphoreGrouping1(t *testing.T) {
func TestPgraphSemaphoreGrouping2(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTestSema("a1", []string{"s:10", "s:11"}))
a2 := pgraph.NewVertex(NewNoopResTestSema("a2", []string{"s:2"}))
a3 := pgraph.NewVertex(NewNoopResTestSema("a3", []string{"s:3"}))
a1 := NewNoopResTestSema("a1", []string{"s:10", "s:11"})
a2 := NewNoopResTestSema("a2", []string{"s:2"})
a3 := NewNoopResTestSema("a3", []string{"s:3"})
g1.AddVertex(a1)
g1.AddVertex(a2)
g1.AddVertex(a3)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a123 := pgraph.NewVertex(NewNoopResTestSema("a1,a2,a3", []string{"s:10", "s:11", "s:2", "s:3"}))
a123 := NewNoopResTestSema("a1,a2,a3", []string{"s:10", "s:11", "s:2", "s:3"})
g2.AddVertex(a123)
}
runGraphCmp(t, g1, g2)
@@ -90,16 +90,16 @@ func TestPgraphSemaphoreGrouping2(t *testing.T) {
func TestPgraphSemaphoreGrouping3(t *testing.T) {
g1, _ := pgraph.NewGraph("g1") // original graph
{
a1 := pgraph.NewVertex(NewNoopResTestSema("a1", []string{"s:1", "s:2"}))
a2 := pgraph.NewVertex(NewNoopResTestSema("a2", []string{"s:2"}))
a3 := pgraph.NewVertex(NewNoopResTestSema("a3", []string{"s:3"}))
a1 := NewNoopResTestSema("a1", []string{"s:1", "s:2"})
a2 := NewNoopResTestSema("a2", []string{"s:2"})
a3 := NewNoopResTestSema("a3", []string{"s:3"})
g1.AddVertex(a1)
g1.AddVertex(a2)
g1.AddVertex(a3)
}
g2, _ := pgraph.NewGraph("g2") // expected result
{
a123 := pgraph.NewVertex(NewNoopResTestSema("a1,a2,a3", []string{"s:1", "s:2", "s:3"}))
a123 := NewNoopResTestSema("a1,a2,a3", []string{"s:1", "s:2", "s:3"})
g2.AddVertex(a123)
}
runGraphCmp(t, g1, g2)

View File

@@ -68,9 +68,8 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
MetaParams: metaparams,
},
}
v := pgraph.NewVertex(n0)
g.AddVertex(n0)
g.AddVertex(v)
//g, err := config.NewGraphFromConfig(obj.data.Hostname, obj.data.World, obj.data.Noop)
return g, nil
}

View File

@@ -145,7 +145,7 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World,
return nil, errwrap.Wrapf(err, "could not VertexMatchFn() resource")
}
if v == nil { // no match found
v = pgraph.NewVertex(res)
v = res // a standalone res can be a vertex
graph.AddVertex(v) // call standalone in case not part of an edge
}
lookup[kind][res.GetName()] = v // used for constructing edges
@@ -223,7 +223,7 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World,
return nil, errwrap.Wrapf(err, "could not VertexMatchFn() resource")
}
if v == nil { // no match found
v = pgraph.NewVertex(res)
v = res // a standalone res can be a vertex
graph.AddVertex(v) // call standalone in case not part of an edge
}
lookup[kind][res.GetName()] = v // used for constructing edges

View File

@@ -190,7 +190,7 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World,
return nil, errwrap.Wrapf(err, "could not VertexMatchFn() resource")
}
if v == nil { // no match found
v = pgraph.NewVertex(res)
v = res // a standalone res can be a vertex
graph.AddVertex(v) // call standalone in case not part of an edge
}
lookup[kind][res.GetName()] = v // used for constructing edges
@@ -268,7 +268,7 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World,
return nil, errwrap.Wrapf(err, "could not VertexMatchFn() resource")
}
if v == nil { // no match found
v = pgraph.NewVertex(res)
v = res // a standalone res can be a vertex
graph.AddVertex(v) // call standalone in case not part of an edge
}
lookup[kind][res.GetName()] = v // used for constructing edges