command: Fix tests for "terraform fmt" command

Some underlying assumptions have shifted here, so although the behavior
is still broadly the same we need to accommodate some different details.
This commit is contained in:
Martin Atkins 2018-10-13 08:19:54 -07:00
parent 74582447bb
commit c0baedac84
1 changed files with 9 additions and 4 deletions

View File

@ -29,7 +29,7 @@ func TestFmt_errorReporting(t *testing.T) {
t.Fatalf("wrong exit code. errors: \n%s", ui.ErrorWriter.String())
}
expected := fmt.Sprintf("Error running fmt: stat %s: no such file or directory", dummy_file)
expected := "There is no configuration directory at"
if actual := ui.ErrorWriter.String(); !strings.Contains(actual, expected) {
t.Fatalf("expected:\n%s\n\nto include: %q", actual, expected)
}
@ -106,9 +106,14 @@ func TestFmt_directoryArg(t *testing.T) {
t.Fatalf("wrong exit code. errors: \n%s", ui.ErrorWriter.String())
}
expected := fmt.Sprintf("%s\n", filepath.Join(tempDir, fmtFixture.filename))
if actual := ui.OutputWriter.String(); actual != expected {
t.Fatalf("got: %q\nexpected: %q", actual, expected)
got, err := filepath.Abs(strings.TrimSpace(ui.OutputWriter.String()))
if err != nil {
t.Fatal(err)
}
want := filepath.Join(tempDir, fmtFixture.filename)
if got != want {
t.Fatalf("wrong output\ngot: %s\nwant: %s", got, want)
}
}