terraform/command/remote_push_test.go

70 lines
1.3 KiB
Go
Raw Normal View History

2014-10-09 00:15:14 +02:00
package command
import (
2015-02-22 20:07:51 +01:00
"os"
"path/filepath"
2014-10-09 00:15:14 +02:00
"testing"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/cli"
)
func TestRemotePush_noRemote(t *testing.T) {
2014-10-09 00:15:14 +02:00
tmp, cwd := testCwd(t)
2014-10-09 23:45:08 +02:00
defer testFixCwd(t, tmp, cwd)
2014-10-09 00:15:14 +02:00
ui := new(cli.MockUi)
c := &RemotePushCommand{
2014-10-09 00:15:14 +02:00
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
},
}
args := []string{}
if code := c.Run(args); code != 1 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
}
func TestRemotePush_local(t *testing.T) {
2014-10-09 00:15:14 +02:00
tmp, cwd := testCwd(t)
2014-10-09 23:45:08 +02:00
defer testFixCwd(t, tmp, cwd)
2014-10-09 00:15:14 +02:00
s := terraform.NewState()
s.Serial = 5
conf, srv := testRemoteState(t, s, 200)
defer srv.Close()
2014-10-09 00:15:14 +02:00
s = terraform.NewState()
s.Serial = 10
s.Remote = conf
// Store the local state
2015-02-22 20:07:51 +01:00
statePath := filepath.Join(tmp, DefaultDataDir, DefaultStateFilename)
if err := os.MkdirAll(filepath.Dir(statePath), 0755); err != nil {
t.Fatalf("err: %s", err)
}
f, err := os.Create(statePath)
if err != nil {
t.Fatalf("err: %s", err)
}
err = terraform.WriteState(s, f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
2014-10-09 00:15:14 +02:00
ui := new(cli.MockUi)
c := &RemotePushCommand{
2014-10-09 00:15:14 +02:00
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
},
}
args := []string{}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
}