|
|
|
|
@ -179,7 +179,9 @@ func TestPush_inputPartial(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPush_inputTfvars(t *testing.T) {
|
|
|
|
|
// This tests that the push command will override Atlas variables
|
|
|
|
|
// if requested.
|
|
|
|
|
func TestPush_localOverride(t *testing.T) {
|
|
|
|
|
// Disable test mode so input would be asked and setup the
|
|
|
|
|
// input reader/writers.
|
|
|
|
|
test = false
|
|
|
|
|
@ -219,6 +221,154 @@ func TestPush_inputTfvars(t *testing.T) {
|
|
|
|
|
client: client,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path := testFixturePath("push-tfvars")
|
|
|
|
|
args := []string{
|
|
|
|
|
"-var-file", path + "/terraform.tfvars",
|
|
|
|
|
"-vcs=false",
|
|
|
|
|
"-set=foo",
|
|
|
|
|
path,
|
|
|
|
|
}
|
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
actual := testArchiveStr(t, archivePath)
|
|
|
|
|
expected := []string{
|
|
|
|
|
".terraform/",
|
|
|
|
|
".terraform/terraform.tfstate",
|
|
|
|
|
"main.tf",
|
|
|
|
|
"terraform.tfvars",
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if client.UpsertOptions.Name != "foo" {
|
|
|
|
|
t.Fatalf("bad: %#v", client.UpsertOptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variables := map[string]string{
|
|
|
|
|
"foo": "bar",
|
|
|
|
|
"bar": "foo",
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(client.UpsertOptions.Variables, variables) {
|
|
|
|
|
t.Fatalf("bad: %#v", client.UpsertOptions)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This tests that the push command prefers Atlas variables over
|
|
|
|
|
// local ones.
|
|
|
|
|
func TestPush_preferAtlas(t *testing.T) {
|
|
|
|
|
// Disable test mode so input would be asked and setup the
|
|
|
|
|
// input reader/writers.
|
|
|
|
|
test = false
|
|
|
|
|
defer func() { test = true }()
|
|
|
|
|
defaultInputReader = bytes.NewBufferString("nope\n")
|
|
|
|
|
defaultInputWriter = new(bytes.Buffer)
|
|
|
|
|
|
|
|
|
|
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}
|
|
|
|
|
// Provided vars should override existing ones
|
|
|
|
|
client.GetResult = map[string]string{
|
|
|
|
|
"foo": "old",
|
|
|
|
|
}
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
|
c := &PushCommand{
|
|
|
|
|
Meta: Meta{
|
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
|
Ui: ui,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
client: client,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path := testFixturePath("push-tfvars")
|
|
|
|
|
args := []string{
|
|
|
|
|
"-var-file", path + "/terraform.tfvars",
|
|
|
|
|
"-vcs=false",
|
|
|
|
|
path,
|
|
|
|
|
}
|
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
actual := testArchiveStr(t, archivePath)
|
|
|
|
|
expected := []string{
|
|
|
|
|
".terraform/",
|
|
|
|
|
".terraform/terraform.tfstate",
|
|
|
|
|
"main.tf",
|
|
|
|
|
"terraform.tfvars",
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if client.UpsertOptions.Name != "foo" {
|
|
|
|
|
t.Fatalf("bad: %#v", client.UpsertOptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variables := map[string]string{
|
|
|
|
|
"foo": "old",
|
|
|
|
|
"bar": "foo",
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(client.UpsertOptions.Variables, variables) {
|
|
|
|
|
t.Fatalf("bad: %#v", client.UpsertOptions)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This tests that the push command will send the variables in tfvars
|
|
|
|
|
func TestPush_tfvars(t *testing.T) {
|
|
|
|
|
// Disable test mode so input would be asked and setup the
|
|
|
|
|
// input reader/writers.
|
|
|
|
|
test = false
|
|
|
|
|
defer func() { test = true }()
|
|
|
|
|
defaultInputReader = bytes.NewBufferString("nope\n")
|
|
|
|
|
defaultInputWriter = new(bytes.Buffer)
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path := testFixturePath("push-tfvars")
|
|
|
|
|
args := []string{
|
|
|
|
|
"-var-file", path + "/terraform.tfvars",
|
|
|
|
|
|