command/push: test that input is asked

This commit is contained in:
Mitchell Hashimoto 2015-03-06 14:49:22 -08:00
parent d37d9ea6ef
commit bf14143369
3 changed files with 56 additions and 2 deletions

View File

@ -1,7 +1,6 @@
package command
import (
"flag"
"fmt"
"io"
"os"
@ -24,7 +23,7 @@ func (c *PushCommand) Run(args []string) int {
var atlasToken string
var moduleLock bool
args = c.Meta.process(args, false)
cmdFlags := flag.NewFlagSet("push", flag.ContinueOnError)
cmdFlags := c.Meta.flagSet("push")
cmdFlags.StringVar(&c.Meta.statePath, "state", DefaultStateFilename, "path")
cmdFlags.StringVar(&atlasToken, "token", "", "")
cmdFlags.BoolVar(&moduleLock, "module-lock", true, "")

View File

@ -2,6 +2,7 @@ package command
import (
"archive/tar"
"bytes"
"compress/gzip"
"io"
"os"
@ -65,6 +66,57 @@ func TestPush_good(t *testing.T) {
}
}
func TestPush_input(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
// Create remote state file, this should be pulled
conf, srv := testRemoteState(t, testState(), 200)
defer srv.Close()
// Persist local remote state
s := terraform.NewState()
s.Serial = 5
s.Remote = conf
testStateFileRemote(t, s)
// Path where the archive will be "uploaded" to
archivePath := testTempFile(t)
defer os.Remove(archivePath)
client := &mockPushClient{File: archivePath}
ui := new(cli.MockUi)
c := &PushCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
},
client: client,
}
// Disable test mode so input would be asked and setup the
// input reader/writers.
test = false
defer func() { test = true }()
defaultInputReader = bytes.NewBufferString("foo\n")
defaultInputWriter = new(bytes.Buffer)
args := []string{
testFixturePath("push-input"),
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
variables := map[string]string{
"foo": "foo",
}
if !reflect.DeepEqual(client.UpsertOptions.Variables, variables) {
t.Fatalf("bad: %#v", client.UpsertOptions)
}
}
func TestPush_noState(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)

View File

@ -0,0 +1,3 @@
variable "foo" {}
resource "test_instance" "foo" {}