Skip to content

Commit

Permalink
Include inEdges in Graph String()
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi committed Jan 13, 2025
1 parent eaaab21 commit 1914a3c
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions pkg/graph/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package graph

import (
"fmt"
"strings"

eventingv1beta3 "knative.dev/eventing/pkg/apis/eventing/v1beta3"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"

eventingv1beta3 "knative.dev/eventing/pkg/apis/eventing/v1beta3"
)

type Graph struct {
Expand Down Expand Up @@ -109,12 +111,6 @@ func (g *Graph) String() string {
s := ""
for _, v := range g.vertices {
s += fmt.Sprintf("%s\n", v)
if len(v.outEdges) != 0 {
s += "Out Edges:\n"
for _, e := range v.outEdges {
s += fmt.Sprintf("\t%s\n", e)
}
}
}

return s
Expand Down Expand Up @@ -182,7 +178,23 @@ func (v *Vertex) AddEdge(to *Vertex, edgeRef *duckv1.Destination, transform Tran
}

func (v *Vertex) String() string {
return DestString(v.self)
sb := strings.Builder{}
sb.WriteString(DestString(v.self))
if v.OutDegree() > 0 {
sb.WriteString("\n\tOut Edges:")
for _, e := range v.outEdges {
sb.WriteString("\n\t\t")
sb.WriteString(e.String())
}
}
if v.InDegree() > 0 {
sb.WriteString("\n\tIn Edges:")
for _, e := range v.inEdges {
sb.WriteString("\n\t\t")
sb.WriteString(e.String())
}
}
return sb.String()
}

func (g *Graph) GetPrimaryOutEdgeWithRef(edgeRef *duckv1.KReference) *Edge {
Expand Down

0 comments on commit 1914a3c

Please sign in to comment.