command/fmt: Test non-default options

To ensure that these are passed over to `fmtcmd` correctly.
This commit is contained in:
Dan Carley 2016-02-02 22:10:23 +00:00
parent 79e2753e41
commit d883b76070
1 changed files with 31 additions and 0 deletions

View File

@ -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