GraphNodeExpand is not used
This commit is contained in:
parent
be2629d2f9
commit
a104ecb69d
|
@ -101,19 +101,6 @@ func (g *Graph) walk(walker GraphWalker) tfdiags.Diagnostics {
|
||||||
log.Printf("[TRACE] vertex %q: produced no dynamic subgraph", dag.VertexName(v))
|
log.Printf("[TRACE] vertex %q: produced no dynamic subgraph", dag.VertexName(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the node has a subgraph, then walk the subgraph
|
|
||||||
if sn, ok := v.(GraphNodeSubgraph); ok {
|
|
||||||
log.Printf("[TRACE] vertex %q: entering static subgraph", dag.VertexName(v))
|
|
||||||
|
|
||||||
subDiags := sn.Subgraph().(*Graph).walk(walker)
|
|
||||||
if subDiags.HasErrors() {
|
|
||||||
log.Printf("[TRACE] vertex %q: static subgraph encountered errors", dag.VertexName(v))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Printf("[TRACE] vertex %q: static subgraph completed successfully", dag.VertexName(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,5 @@
|
||||||
package terraform
|
package terraform
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/dag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GraphNodeExapndable is an interface that nodes can implement to
|
|
||||||
// signal that they can be expanded. Expanded nodes turn into
|
|
||||||
// GraphNodeSubgraph nodes within the graph.
|
|
||||||
type GraphNodeExpandable interface {
|
|
||||||
Expand(GraphBuilder) (GraphNodeSubgraph, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GraphNodeDynamicExpandable is an interface that nodes can implement
|
// GraphNodeDynamicExpandable is an interface that nodes can implement
|
||||||
// to signal that they can be expanded at eval-time (hence dynamic).
|
// to signal that they can be expanded at eval-time (hence dynamic).
|
||||||
// These nodes are given the eval context and are expected to return
|
// These nodes are given the eval context and are expected to return
|
||||||
|
@ -20,29 +7,3 @@ type GraphNodeExpandable interface {
|
||||||
type GraphNodeDynamicExpandable interface {
|
type GraphNodeDynamicExpandable interface {
|
||||||
DynamicExpand(EvalContext) (*Graph, error)
|
DynamicExpand(EvalContext) (*Graph, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GraphNodeSubgraph is an interface a node can implement if it has
|
|
||||||
// a larger subgraph that should be walked.
|
|
||||||
type GraphNodeSubgraph interface {
|
|
||||||
Subgraph() dag.Grapher
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpandTransform is a transformer that does a subgraph expansion
|
|
||||||
// at graph transform time (vs. at eval time). The benefit of earlier
|
|
||||||
// subgraph expansion is that errors with the graph build can be detected
|
|
||||||
// at an earlier stage.
|
|
||||||
type ExpandTransform struct {
|
|
||||||
Builder GraphBuilder
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ExpandTransform) Transform(v dag.Vertex) (dag.Vertex, error) {
|
|
||||||
ev, ok := v.(GraphNodeExpandable)
|
|
||||||
if !ok {
|
|
||||||
// This isn't an expandable vertex, so just ignore it.
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expand the subgraph!
|
|
||||||
log.Printf("[DEBUG] vertex %q: static expanding", dag.VertexName(ev))
|
|
||||||
return ev.Expand(t.Builder)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
package terraform
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/dag"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestExpandTransform_impl(t *testing.T) {
|
|
||||||
var _ GraphVertexTransformer = new(ExpandTransform)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExpandTransform(t *testing.T) {
|
|
||||||
var g Graph
|
|
||||||
g.Add(1)
|
|
||||||
g.Add(2)
|
|
||||||
g.Connect(dag.BasicEdge(1, 2))
|
|
||||||
|
|
||||||
tf := &ExpandTransform{}
|
|
||||||
out, err := tf.Transform(&testExpandable{
|
|
||||||
Result: &g,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sn, ok := out.(GraphNodeSubgraph)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("not subgraph: %#v", out)
|
|
||||||
}
|
|
||||||
|
|
||||||
actual := strings.TrimSpace(sn.Subgraph().(*Graph).String())
|
|
||||||
expected := strings.TrimSpace(testExpandTransformStr)
|
|
||||||
if actual != expected {
|
|
||||||
t.Fatalf("bad: %s", actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExpandTransform_nonExpandable(t *testing.T) {
|
|
||||||
tf := &ExpandTransform{}
|
|
||||||
out, err := tf.Transform(42)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
if out != 42 {
|
|
||||||
t.Fatalf("bad: %#v", out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type testExpandable struct {
|
|
||||||
// Inputs
|
|
||||||
Result *Graph
|
|
||||||
ResultError error
|
|
||||||
|
|
||||||
// Outputs
|
|
||||||
Builder GraphBuilder
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *testExpandable) Expand(b GraphBuilder) (GraphNodeSubgraph, error) {
|
|
||||||
n.Builder = b
|
|
||||||
return &testSubgraph{n.Result}, n.ResultError
|
|
||||||
}
|
|
||||||
|
|
||||||
type testSubgraph struct {
|
|
||||||
Graph *Graph
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *testSubgraph) Subgraph() dag.Grapher {
|
|
||||||
return n.Graph
|
|
||||||
}
|
|
||||||
|
|
||||||
const testExpandTransformStr = `
|
|
||||||
1
|
|
||||||
2
|
|
||||||
2
|
|
||||||
`
|
|
Loading…
Reference in New Issue