terraform: delete proxy transformer
This commit is contained in:
parent
ca0550e7eb
commit
e8eb0bd92f
|
@ -10,12 +10,10 @@ func TestGraphNodeConfigVariable_impl(t *testing.T) {
|
||||||
var _ dag.Vertex = new(GraphNodeConfigVariable)
|
var _ dag.Vertex = new(GraphNodeConfigVariable)
|
||||||
var _ dag.NamedVertex = new(GraphNodeConfigVariable)
|
var _ dag.NamedVertex = new(GraphNodeConfigVariable)
|
||||||
var _ graphNodeConfig = new(GraphNodeConfigVariable)
|
var _ graphNodeConfig = new(GraphNodeConfigVariable)
|
||||||
var _ GraphNodeProxy = new(GraphNodeConfigVariable)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGraphNodeConfigVariableFlat_impl(t *testing.T) {
|
func TestGraphNodeConfigVariableFlat_impl(t *testing.T) {
|
||||||
var _ dag.Vertex = new(GraphNodeConfigVariableFlat)
|
var _ dag.Vertex = new(GraphNodeConfigVariableFlat)
|
||||||
var _ dag.NamedVertex = new(GraphNodeConfigVariableFlat)
|
var _ dag.NamedVertex = new(GraphNodeConfigVariableFlat)
|
||||||
var _ graphNodeConfig = new(GraphNodeConfigVariableFlat)
|
var _ graphNodeConfig = new(GraphNodeConfigVariableFlat)
|
||||||
var _ GraphNodeProxy = new(GraphNodeConfigVariableFlat)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
package terraform
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/hashicorp/terraform/dag"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GraphNodeProxy must be implemented by nodes that are proxies.
|
|
||||||
//
|
|
||||||
// A node that is a proxy says that anything that depends on this
|
|
||||||
// node (the proxy), should also copy all the things that the proxy
|
|
||||||
// itself depends on. Example:
|
|
||||||
//
|
|
||||||
// A => proxy => C
|
|
||||||
//
|
|
||||||
// Should transform into (two edges):
|
|
||||||
//
|
|
||||||
// A => proxy => C
|
|
||||||
// A => C
|
|
||||||
//
|
|
||||||
// The purpose for this is because some transforms only look at direct
|
|
||||||
// edge connections and the proxy generally isn't meaningful in those
|
|
||||||
// situations, so we should complete all the edges.
|
|
||||||
type GraphNodeProxy interface {
|
|
||||||
Proxy() bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProxyTransformer is a transformer that goes through the graph, finds
|
|
||||||
// vertices that are marked as proxies, and connects through their
|
|
||||||
// dependents. See above for what a proxy is.
|
|
||||||
type ProxyTransformer struct{}
|
|
||||||
|
|
||||||
func (t *ProxyTransformer) Transform(g *Graph) error {
|
|
||||||
for _, v := range g.Vertices() {
|
|
||||||
pn, ok := v.(GraphNodeProxy)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we don't want to be proxies, don't do it
|
|
||||||
if !pn.Proxy() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect all the things that depend on this to things that
|
|
||||||
// we depend on as the proxy. See docs for GraphNodeProxy for
|
|
||||||
// a visual explanation.
|
|
||||||
for _, s := range g.UpEdges(v).List() {
|
|
||||||
for _, t := range g.DownEdges(v).List() {
|
|
||||||
g.Connect(GraphProxyEdge{
|
|
||||||
Edge: dag.BasicEdge(s, t),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GraphProxyEdge is the edge that is used for proxied edges.
|
|
||||||
type GraphProxyEdge struct {
|
|
||||||
dag.Edge
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
package terraform
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/dag"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestProxyTransformer(t *testing.T) {
|
|
||||||
var g Graph
|
|
||||||
proxy := &testNodeProxy{NameValue: "proxy"}
|
|
||||||
g.Add("A")
|
|
||||||
g.Add("C")
|
|
||||||
g.Add(proxy)
|
|
||||||
g.Connect(dag.BasicEdge("A", proxy))
|
|
||||||
g.Connect(dag.BasicEdge(proxy, "C"))
|
|
||||||
|
|
||||||
{
|
|
||||||
tf := &ProxyTransformer{}
|
|
||||||
if err := tf.Transform(&g); err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
actual := strings.TrimSpace(g.String())
|
|
||||||
expected := strings.TrimSpace(testProxyTransformStr)
|
|
||||||
if actual != expected {
|
|
||||||
t.Fatalf("bad: %s", actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type testNodeProxy struct {
|
|
||||||
NameValue string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *testNodeProxy) Name() string {
|
|
||||||
return n.NameValue
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *testNodeProxy) Proxy() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
const testProxyTransformStr = `
|
|
||||||
A
|
|
||||||
C
|
|
||||||
proxy
|
|
||||||
C
|
|
||||||
proxy
|
|
||||||
C
|
|
||||||
`
|
|
Loading…
Reference in New Issue