mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
e980156451
Rather than try to modify all the hundreds of calls to the temp helper functions, and cleanup the temp files at every call site, have all tests work within a single temp directory that is removed at the end of TestMain.
54 lines
1015 B
Go
54 lines
1015 B
Go
package command
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/dag"
|
|
"github.com/mitchellh/cli"
|
|
)
|
|
|
|
func TestDebugJSON2Dot(t *testing.T) {
|
|
// create the graph JSON output
|
|
logFile, err := ioutil.TempFile(testingDir, "tf")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.Remove(logFile.Name())
|
|
|
|
var g dag.Graph
|
|
g.SetDebugWriter(logFile)
|
|
|
|
g.Add(1)
|
|
g.Add(2)
|
|
g.Add(3)
|
|
g.Connect(dag.BasicEdge(1, 2))
|
|
g.Connect(dag.BasicEdge(2, 3))
|
|
|
|
ui := new(cli.MockUi)
|
|
c := &DebugJSON2DotCommand{
|
|
Meta: Meta{
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
Ui: ui,
|
|
},
|
|
}
|
|
|
|
args := []string{
|
|
logFile.Name(),
|
|
}
|
|
if code := c.Run(args); code != 0 {
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
}
|
|
|
|
output := ui.OutputWriter.String()
|
|
if !strings.HasPrefix(output, "digraph {") {
|
|
t.Fatalf("doesn't look like digraph: %s", output)
|
|
}
|
|
|
|
if !strings.Contains(output, `subgraph "root" {`) {
|
|
t.Fatalf("doesn't contains root subgraph: %s", output)
|
|
}
|
|
}
|