Skip to content

Commit

Permalink
command/fmt: Test non-default options
Browse files Browse the repository at this point in the history
To ensure that these are passed over to `fmtcmd` correctly.
  • Loading branch information
dcarley committed Feb 8, 2016
1 parent 040acf1 commit 9b6f0cd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions command/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,37 @@ func TestFmt_stdinArg(t *testing.T) {
}
}

func TestFmt_nonDefaultOptions(t *testing.T) {
tempDir, err := fmtFixtureWriteDir()
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.RemoveAll(tempDir)

ui := new(cli.MockUi)
c := &FmtCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
},
}

args := []string{
"-list=false",
"-write=false",
"-diff",
tempDir,
}
if code := c.Run(args); code != 0 {
t.Fatalf("wrong exit code. errors: \n%s", ui.ErrorWriter.String())
}

expected := fmt.Sprintf("-%s+%s", fmtFixture.input, fmtFixture.golden)
if actual := ui.OutputWriter.String(); !strings.Contains(actual, expected) {
t.Fatalf("expected:\n%s\n\nto include: %q", actual, expected)
}
}

var fmtFixture = struct {
filename string
input, golden []byte
Expand Down

0 comments on commit 9b6f0cd

Please sign in to comment.