2017-01-18 22:50:45 -06:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStatePull(t *testing.T) {
|
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
// Create some legacy remote state
|
|
|
|
legacyState := testState()
|
|
|
|
_, srv := testRemoteState(t, legacyState, 200)
|
|
|
|
defer srv.Close()
|
|
|
|
testStateFileRemote(t, legacyState)
|
|
|
|
|
|
|
|
p := testProvider()
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &StatePullCommand{
|
|
|
|
Meta: Meta{
|
2017-04-13 20:05:58 -05:00
|
|
|
testingOverrides: metaOverridesForProvider(p),
|
|
|
|
Ui: ui,
|
2017-01-18 22:50:45 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.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)
|
|
|
|
}
|
|
|
|
}
|
2017-03-01 14:47:36 -06:00
|
|
|
|
|
|
|
func TestStatePull_noState(t *testing.T) {
|
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
defer testFixCwd(t, tmp, cwd)
|
|
|
|
|
|
|
|
p := testProvider()
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
c := &StatePullCommand{
|
|
|
|
Meta: Meta{
|
2017-04-13 20:05:58 -05:00
|
|
|
testingOverrides: metaOverridesForProvider(p),
|
|
|
|
Ui: ui,
|
2017-03-01 14:47:36 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
args := []string{}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
actual := ui.OutputWriter.String()
|
|
|
|
if actual != "" {
|
|
|
|
t.Fatalf("bad: %s", actual)
|
|
|
|
}
|
|
|
|
}
|