opentofu/terraform/graph_builder_test.go
Martin Atkins 4a21b763aa core: Get tests compiling again
After the refactoring to integrate HCL2 many of the tests were no longer
using correct types, attribute names, etc.

This is a bulk update of all of the tests to make them compile again, with
minimal changes otherwise. Although the tests now compile, many of them
do not yet pass. The tests will be gradually repaired in subsequent
commits, as we continue to complete the refactoring and retrofit work.
2018-10-16 18:46:46 -07:00

81 lines
1.5 KiB
Go

package terraform
import (
"strings"
"testing"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/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
`