mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-06 14:13:16 -06:00
36d0a50427
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
81 lines
1.5 KiB
Go
81 lines
1.5 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},
|
|
},
|
|
Validate: true,
|
|
}
|
|
|
|
_, err := b.Build(addrs.RootModuleInstance)
|
|
if err == nil {
|
|
t.Fatal("should error")
|
|
}
|
|
}
|
|
|
|
func TestBasicGraphBuilder_validateOff(t *testing.T) {
|
|
b := &BasicGraphBuilder{
|
|
Steps: []GraphTransformer{
|
|
&testBasicGraphBuilderTransform{1},
|
|
&testBasicGraphBuilderTransform{2},
|
|
},
|
|
Validate: false,
|
|
}
|
|
|
|
_, err := b.Build(addrs.RootModuleInstance)
|
|
if err != nil {
|
|
t.Fatalf("expected no error, got: %s", err)
|
|
}
|
|
}
|
|
|
|
type testBasicGraphBuilderTransform struct {
|
|
V dag.Vertex
|
|
}
|
|
|
|
func (t *testBasicGraphBuilderTransform) Transform(g *Graph) error {
|
|
g.Add(t.V)
|
|
return nil
|
|
}
|
|
|
|
const testBasicGraphBuilderStr = `
|
|
1
|
|
`
|