command/providers: Add regression test

This commit is contained in:
Radek Simko 2017-06-10 12:02:01 +01:00
parent ee30df3efd
commit f5ff67c530
No known key found for this signature in database
GPG Key ID: 6823F3DCCE01BB19
1 changed files with 30 additions and 0 deletions

View File

@ -41,3 +41,33 @@ func TestProviders(t *testing.T) {
t.Errorf("output missing provider.baz\n\n%s", output)
}
}
func TestProviders_noConfigs(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("err: %s", err)
}
if err := os.Chdir(testFixturePath("")); err != nil {
t.Fatalf("err: %s", err)
}
defer os.Chdir(cwd)
ui := new(cli.MockUi)
c := &ProvidersCommand{
Meta: Meta{
Ui: ui,
},
}
args := []string{}
if code := c.Run(args); code == 0 {
t.Fatal("expected command to return non-zero exit code" +
" when no configs are available")
}
output := ui.ErrorWriter.String()
expectedErrMsg := "No configuration files found"
if !strings.Contains(output, expectedErrMsg) {
t.Errorf("Expected error message: %s\nGiven output: %s", expectedErrMsg, output)
}
}