terraform/command/show_test.go

104 lines
2.0 KiB
Go
Raw Normal View History

2014-07-13 04:47:31 +02:00
package command
import (
"path/filepath"
2014-07-13 04:47:31 +02:00
"testing"
"github.com/mitchellh/cli"
)
func TestShow(t *testing.T) {
ui := new(cli.MockUi)
c := &ShowCommand{
2014-07-13 18:22:23 +02:00
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),
Ui: ui,
2014-07-13 18:22:23 +02:00
},
2014-07-13 04:47:31 +02:00
}
args := []string{
"bad",
"bad",
}
if code := c.Run(args); code != 1 {
t.Fatalf("bad: \n%s", ui.OutputWriter.String())
}
}
func TestShow_noArgs(t *testing.T) {
// Create the default state
statePath := testStateFile(t, testState())
defer testChdir(t, filepath.Dir(statePath))()
2014-07-13 04:47:31 +02:00
ui := new(cli.MockUi)
c := &ShowCommand{
2014-07-13 18:22:23 +02:00
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),
Ui: ui,
2014-07-13 18:22:23 +02:00
},
2014-07-13 04:47:31 +02:00
}
args := []string{}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.OutputWriter.String())
}
}
func TestShow_noArgsNoState(t *testing.T) {
// Create the default state
statePath := testStateFile(t, testState())
defer testChdir(t, filepath.Dir(statePath))()
ui := new(cli.MockUi)
c := &ShowCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),
Ui: ui,
},
}
args := []string{}
if code := c.Run(args); code != 0 {
2014-07-13 04:47:31 +02:00
t.Fatalf("bad: \n%s", ui.OutputWriter.String())
}
}
func TestShow_plan(t *testing.T) {
planPath := testPlanFileNoop(t)
2014-07-13 04:47:31 +02:00
ui := new(cli.MockUi)
c := &ShowCommand{
2014-07-13 18:22:23 +02:00
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),
Ui: ui,
2014-07-13 18:22:23 +02:00
},
2014-07-13 04:47:31 +02:00
}
args := []string{
planPath,
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
}
func TestShow_state(t *testing.T) {
2014-09-17 20:15:07 +02:00
originalState := testState()
2014-07-13 04:47:31 +02:00
statePath := testStateFile(t, originalState)
ui := new(cli.MockUi)
c := &ShowCommand{
2014-07-13 18:22:23 +02:00
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),
Ui: ui,
2014-07-13 18:22:23 +02:00
},
2014-07-13 04:47:31 +02:00
}
args := []string{
statePath,
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
}