mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-29 10:21:01 -06:00
0bc69d64ec
Complete the removal of the Validate option for graph building. There is no case where we want to allow an invalid graph, as the primary reason for validation is to ensure we have no cycles, and we can't walk a graph with cycles. The only code which specifically relied on there being no validation was a test to ensure the Validate flag prevented it.
65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
package terraform
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/internal/addrs"
|
|
|
|
"github.com/hashicorp/terraform/internal/dag"
|
|
)
|
|
|
|
func TestBasicGraphBuilder_impl(t *testing.T) {
|
|
var _ GraphBuilder = new(BasicGraphBuilder)
|
|
}
|
|
|
|
func TestBasicGraphBuilder(t *testing.T) {
|
|
b := &BasicGraphBuilder{
|
|
Steps: []GraphTransformer{
|
|
&testBasicGraphBuilderTransform{1},
|
|
},
|
|
}
|
|
|
|
g, err := b.Build(addrs.RootModuleInstance)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if g.Path.String() != addrs.RootModuleInstance.String() {
|
|
t.Fatalf("wrong module path %q", g.Path)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(testBasicGraphBuilderStr)
|
|
if actual != expected {
|
|
t.Fatalf("bad: %s", actual)
|
|
}
|
|
}
|
|
|
|
func TestBasicGraphBuilder_validate(t *testing.T) {
|
|
b := &BasicGraphBuilder{
|
|
Steps: []GraphTransformer{
|
|
&testBasicGraphBuilderTransform{1},
|
|
&testBasicGraphBuilderTransform{2},
|
|
},
|
|
}
|
|
|
|
_, err := b.Build(addrs.RootModuleInstance)
|
|
if err == nil {
|
|
t.Fatal("should error")
|
|
}
|
|
}
|
|
|
|
type testBasicGraphBuilderTransform struct {
|
|
V dag.Vertex
|
|
}
|
|
|
|
func (t *testBasicGraphBuilderTransform) Transform(g *Graph) error {
|
|
g.Add(t.V)
|
|
return nil
|
|
}
|
|
|
|
const testBasicGraphBuilderStr = `
|
|
1
|
|
`
|