forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_pull_test.go
66 lines (55 loc) · 1.31 KB
/
state_pull_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package command
import (
"bytes"
"io/ioutil"
"os"
"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)()
expected, err := ioutil.ReadFile("local-state.tfstate")
if err != nil {
t.Fatalf("error reading state: %v", err)
}
p := testProvider()
ui := new(cli.MockUi)
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.Bytes()
if bytes.Equal(actual, expected) {
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)
}
}