mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -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.
71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package terraform
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/internal/dag"
|
|
)
|
|
|
|
// testGraphContains is an assertion helper that tests that a node is
|
|
// contained in the graph.
|
|
func testGraphContains(t *testing.T, g *Graph, name string) {
|
|
for _, v := range g.Vertices() {
|
|
if dag.VertexName(v) == name {
|
|
return
|
|
}
|
|
}
|
|
|
|
t.Fatalf(
|
|
"Expected %q in:\n\n%s",
|
|
name, g.String())
|
|
}
|
|
|
|
// testGraphnotContains is an assertion helper that tests that a node is
|
|
// NOT contained in the graph.
|
|
func testGraphNotContains(t *testing.T, g *Graph, name string) {
|
|
for _, v := range g.Vertices() {
|
|
if dag.VertexName(v) == name {
|
|
t.Fatalf(
|
|
"Expected %q to NOT be in:\n\n%s",
|
|
name, g.String())
|
|
}
|
|
}
|
|
}
|
|
|
|
// testGraphHappensBefore is an assertion helper that tests that node
|
|
// A (dag.VertexName value) happens before node B.
|
|
func testGraphHappensBefore(t *testing.T, g *Graph, A, B string) {
|
|
t.Helper()
|
|
// Find the B vertex
|
|
var vertexB dag.Vertex
|
|
for _, v := range g.Vertices() {
|
|
if dag.VertexName(v) == B {
|
|
vertexB = v
|
|
break
|
|
}
|
|
}
|
|
if vertexB == nil {
|
|
t.Fatalf(
|
|
"Expected %q before %q. Couldn't find %q in:\n\n%s",
|
|
A, B, B, g.String())
|
|
}
|
|
|
|
// Look at ancestors
|
|
deps, err := g.Ancestors(vertexB)
|
|
if err != nil {
|
|
t.Fatalf("Error: %s in graph:\n\n%s", err, g.String())
|
|
}
|
|
|
|
// Make sure B is in there
|
|
for _, v := range deps.List() {
|
|
if dag.VertexName(v) == A {
|
|
// Success
|
|
return
|
|
}
|
|
}
|
|
|
|
t.Fatalf(
|
|
"Expected %q before %q in:\n\n%s",
|
|
A, B, g.String())
|
|
}
|