Merge pull request #25299 from hashicorp/alisdair/fix-command-fixture-modify-in-place

command: Fix command fixture modify-in-place bugs
This commit is contained in:
Alisdair McDiarmid 2020-06-22 09:47:04 -04:00 committed by GitHub
commit 2fdde395ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 52 deletions

View File

@ -540,7 +540,7 @@ func testChdir(t *testing.T, new string) func() {
}
// testCwd is used to change the current working directory
// into a test directory that should be remoted after
// into a test directory that should be removed after
func testCwd(t *testing.T) (string, string) {
t.Helper()

View File

@ -25,14 +25,10 @@ import (
)
func TestPlan(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("err: %s", err)
}
if err := os.Chdir(testFixturePath("plan")); err != nil {
t.Fatalf("err: %s", err)
}
defer os.Chdir(cwd)
td := tempDir(t)
copy.CopyDir(testFixturePath("plan"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
p := planFixtureProvider()
ui := new(cli.MockUi)
@ -50,23 +46,17 @@ func TestPlan(t *testing.T) {
}
func TestPlan_lockedState(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("err: %s", err)
}
td := tempDir(t)
copy.CopyDir(testFixturePath("plan"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
testPath := testFixturePath("plan")
unlock, err := testLockState(testDataDir, filepath.Join(testPath, DefaultStateFilename))
unlock, err := testLockState(testDataDir, filepath.Join(td, DefaultStateFilename))
if err != nil {
t.Fatal(err)
}
defer unlock()
if err := os.Chdir(testPath); err != nil {
t.Fatalf("err: %s", err)
}
defer os.Chdir(cwd)
p := planFixtureProvider()
ui := new(cli.MockUi)
c := &PlanCommand{
@ -489,14 +479,10 @@ func TestPlan_validate(t *testing.T) {
test = false
defer func() { test = true }()
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("err: %s", err)
}
if err := os.Chdir(testFixturePath("plan-invalid")); err != nil {
t.Fatalf("err: %s", err)
}
defer os.Chdir(cwd)
td := tempDir(t)
copy.CopyDir(testFixturePath("plan-invalid"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
p := testProvider()
p.GetSchemaReturn = &terraform.ProviderSchema{
@ -726,14 +712,10 @@ func TestPlan_varFileWithDecls(t *testing.T) {
}
func TestPlan_detailedExitcode(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("err: %s", err)
}
if err := os.Chdir(testFixturePath("plan")); err != nil {
t.Fatalf("err: %s", err)
}
defer os.Chdir(cwd)
td := tempDir(t)
copy.CopyDir(testFixturePath("plan"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
p := planFixtureProvider()
ui := new(cli.MockUi)
@ -751,14 +733,10 @@ func TestPlan_detailedExitcode(t *testing.T) {
}
func TestPlan_detailedExitcode_emptyDiff(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("err: %s", err)
}
if err := os.Chdir(testFixturePath("plan-emptydiff")); err != nil {
t.Fatalf("err: %s", err)
}
defer os.Chdir(cwd)
td := tempDir(t)
copy.CopyDir(testFixturePath("plan-emptydiff"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
p := testProvider()
ui := new(cli.MockUi)
@ -855,14 +833,10 @@ func TestPlan_shutdown(t *testing.T) {
}
func TestPlan_init_required(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatalf("err: %s", err)
}
if err := os.Chdir(testFixturePath("plan")); err != nil {
t.Fatalf("err: %s", err)
}
defer os.Chdir(cwd)
td := tempDir(t)
copy.CopyDir(testFixturePath("plan"), td)
defer os.RemoveAll(td)
defer testChdir(t, td)()
ui := new(cli.MockUi)
c := &PlanCommand{