command: tests should move to temporary cwd

This fixes any issues where rogue tfstate files may appear in the cwd
otherwise.
This commit is contained in:
Mitchell Hashimoto 2017-02-07 09:11:48 -08:00
parent 1ab17bf5d3
commit 0c97c5a3d9
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 30 additions and 0 deletions

View File

@ -9,6 +9,9 @@ import (
) )
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &GetCommand{ c := &GetCommand{
Meta: Meta{ Meta: Meta{
@ -87,6 +90,9 @@ func TestGet_noArgs(t *testing.T) {
} }
func TestGet_update(t *testing.T) { func TestGet_update(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &GetCommand{ c := &GetCommand{
Meta: Meta{ Meta: Meta{

View File

@ -10,6 +10,9 @@ import (
) )
func TestGraph(t *testing.T) { func TestGraph(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &GraphCommand{ c := &GraphCommand{
Meta: Meta{ Meta: Meta{
@ -79,6 +82,9 @@ func TestGraph_noArgs(t *testing.T) {
} }
func TestGraph_plan(t *testing.T) { func TestGraph_plan(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
planPath := testPlanFile(t, &terraform.Plan{ planPath := testPlanFile(t, &terraform.Plan{
Diff: &terraform.Diff{ Diff: &terraform.Diff{
Modules: []*terraform.ModuleDiff{ Modules: []*terraform.ModuleDiff{

View File

@ -191,6 +191,9 @@ func TestPlan_noState(t *testing.T) {
} }
func TestPlan_outPath(t *testing.T) { func TestPlan_outPath(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
tf, err := ioutil.TempFile("", "tf") tf, err := ioutil.TempFile("", "tf")
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
@ -402,6 +405,9 @@ func TestPlan_outBackendLegacy(t *testing.T) {
} }
func TestPlan_refresh(t *testing.T) { func TestPlan_refresh(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &PlanCommand{ c := &PlanCommand{
@ -619,6 +625,9 @@ func TestPlan_validate(t *testing.T) {
} }
func TestPlan_vars(t *testing.T) { func TestPlan_vars(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
p := testProvider() p := testProvider()
ui := new(cli.MockUi) ui := new(cli.MockUi)
c := &PlanCommand{ c := &PlanCommand{
@ -654,6 +663,9 @@ func TestPlan_vars(t *testing.T) {
} }
func TestPlan_varsUnset(t *testing.T) { func TestPlan_varsUnset(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
// Disable test mode so input would be asked // Disable test mode so input would be asked
test = false test = false
defer func() { test = true }() defer func() { test = true }()
@ -678,6 +690,9 @@ func TestPlan_varsUnset(t *testing.T) {
} }
func TestPlan_varFile(t *testing.T) { func TestPlan_varFile(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
varFilePath := testTempFile(t) varFilePath := testTempFile(t)
if err := ioutil.WriteFile(varFilePath, []byte(planVarFile), 0644); err != nil { if err := ioutil.WriteFile(varFilePath, []byte(planVarFile), 0644); err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)

View File

@ -25,6 +25,9 @@ func testStateBackups(t *testing.T, dir string) []string {
} }
func TestStateDefaultBackupExtension(t *testing.T) { func TestStateDefaultBackupExtension(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
s, err := (&StateMeta{}).State(&Meta{}) s, err := (&StateMeta{}).State(&Meta{})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)