opentofu/internal/tofu/transform_vertex_test.go
namgyalangmo cb2e9119aa
Update copyright notice (#1232)
Signed-off-by: namgyalangmo <75657887+namgyalangmo@users.noreply.github.com>
2024-02-08 09:48:59 +00:00

64 lines
1.1 KiB
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package tofu
import (
"strings"
"testing"
"github.com/opentofu/opentofu/internal/dag"
)
func TestVertexTransformer_impl(t *testing.T) {
var _ GraphTransformer = new(VertexTransformer)
}
func TestVertexTransformer(t *testing.T) {
var g Graph
g.Add(1)
g.Add(2)
g.Add(3)
g.Connect(dag.BasicEdge(1, 2))
g.Connect(dag.BasicEdge(2, 3))
{
tf := &VertexTransformer{
Transforms: []GraphVertexTransformer{
&testVertexTransform{Source: 2, Target: 42},
},
}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testVertexTransformerStr)
if actual != expected {
t.Fatalf("bad: %s", actual)
}
}
type testVertexTransform struct {
Source, Target dag.Vertex
}
func (t *testVertexTransform) Transform(v dag.Vertex) (dag.Vertex, error) {
if t.Source == v {
v = t.Target
}
return v, nil
}
const testVertexTransformerStr = `
1
42
3
42
3
`