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 TestPush_noRemote(t *testing.T) {
|
|
|
|
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 := &PushCommand{
|
|
|
|
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 TestPush_local(t *testing.T) {
|
|
|
|
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)
|
2014-10-09 02:39:08 +02:00
|
|
|
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 := &PushCommand{
|
|
|
|
Meta: Meta{
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
args := []string{}
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
}
|