opentofu/command/state_pull_test.go

67 lines
1.3 KiB
Go
Raw Normal View History

2017-01-18 22:50:45 -06:00
package command
import (
"bytes"
"io/ioutil"
"os"
2017-01-18 22:50:45 -06:00
"testing"
"github.com/mitchellh/cli"
)
func TestStatePull(t *testing.T) {
// Create a temporary working directory that is empty
td := tempDir(t)
testCopyDir(t, testFixturePath("state-pull-backend"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
2017-01-18 22:50:45 -06:00
expected, err := ioutil.ReadFile("local-state.tfstate")
if err != nil {
t.Fatalf("error reading state: %v", err)
}
2017-01-18 22:50:45 -06:00
p := testProvider()
ui := new(cli.MockUi)
c := &StatePullCommand{
Meta: Meta{
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())
}
actual := ui.OutputWriter.Bytes()
if bytes.Equal(actual, expected) {
2017-01-18 22:50:45 -06:00
t.Fatalf("expected:\n%s\n\nto include: %q", actual, expected)
}
}
func TestStatePull_noState(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
p := testProvider()
ui := cli.NewMockUi()
c := &StatePullCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(p),
Ui: ui,
},
}
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)
}
}