2014-07-13 04:47:31 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2014-10-11 21:56:55 +02:00
|
|
|
"path/filepath"
|
2015-06-16 19:26:04 +02:00
|
|
|
"strings"
|
2014-07-13 04:47:31 +02:00
|
|
|
"testing"
|
|
|
|
|
2018-05-23 04:33:45 +02:00
|
|
|
"github.com/hashicorp/terraform/configs"
|
|
|
|
|
2014-07-13 04:47:31 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
"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{
|
2017-04-14 03:05:58 +02:00
|
|
|
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) {
|
2014-10-11 21:56:55 +02:00
|
|
|
// Create the default state
|
2018-03-28 19:08:38 +02:00
|
|
|
statePath := testStateFile(t, testState())
|
|
|
|
defer testChdir(t, filepath.Dir(statePath))()
|
2014-10-11 21:56:55 +02:00
|
|
|
|
2014-07-13 04:47:31 +02:00
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &ShowCommand{
|
2014-07-13 18:22:23 +02:00
|
|
|
Meta: Meta{
|
2017-04-14 03:05:58 +02:00
|
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
|
|
Ui: ui,
|
2014-07-13 18:22:23 +02:00
|
|
|
},
|
2014-07-13 04:47:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{}
|
2014-10-11 21:56:55 +02:00
|
|
|
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
|
2018-03-28 19:08:38 +02:00
|
|
|
statePath := testStateFile(t, testState())
|
|
|
|
defer testChdir(t, filepath.Dir(statePath))()
|
2014-10-11 21:56:55 +02:00
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &ShowCommand{
|
|
|
|
Meta: Meta{
|
2017-04-14 03:05:58 +02:00
|
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
|
|
Ui: ui,
|
2014-10-11 21:56:55 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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 := testPlanFile(t, &terraform.Plan{
|
2018-05-23 04:33:45 +02:00
|
|
|
Config: configs.NewEmptyConfig(),
|
2014-07-13 04:47:31 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &ShowCommand{
|
2014-07-13 18:22:23 +02:00
|
|
|
Meta: Meta{
|
2017-04-14 03:05:58 +02:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 19:26:04 +02:00
|
|
|
func TestShow_noArgsRemoteState(t *testing.T) {
|
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
2017-01-19 05:50:45 +01:00
|
|
|
// Create some legacy remote state
|
|
|
|
legacyState := testState()
|
|
|
|
_, srv := testRemoteState(t, legacyState, 200)
|
|
|
|
defer srv.Close()
|
|
|
|
testStateFileRemote(t, legacyState)
|
2015-06-16 19:26:04 +02:00
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &ShowCommand{
|
|
|
|
Meta: Meta{
|
2017-04-14 03:05:58 +02:00
|
|
|
testingOverrides: metaOverridesForProvider(testProvider()),
|
|
|
|
Ui: ui,
|
2015-06-16 19:26:04 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.OutputWriter.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := "test_instance.foo"
|
|
|
|
actual := ui.OutputWriter.String()
|
|
|
|
if !strings.Contains(actual, expected) {
|
|
|
|
t.Fatalf("expected:\n%s\n\nto include: %q", actual, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-13 04:47:31 +02:00
|
|
|
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{
|
2017-04-14 03:05:58 +02:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|