Add source path argument to testLockState
The new test pattern is to chdir into a temp location for the test, but the prevents us from locating the testdata directory in the source. Add a source path to testLockState so we can find the statelocker.go source.
This commit is contained in:
parent
9fbc5b1ff6
commit
b80ae5e13e
|
@ -111,7 +111,7 @@ func TestApply_destroyLockedState(t *testing.T) {
|
|||
|
||||
statePath := testStateFile(t, originalState)
|
||||
|
||||
unlock, err := testLockState(statePath)
|
||||
unlock, err := testLockState("./testdata", statePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func TestApply(t *testing.T) {
|
|||
func TestApply_lockedState(t *testing.T) {
|
||||
statePath := testTempFile(t)
|
||||
|
||||
unlock, err := testLockState(statePath)
|
||||
unlock, err := testLockState("./testdata", statePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -535,7 +535,9 @@ func testRemoteState(t *testing.T, s *terraform.State, c int) (*terraform.Remote
|
|||
|
||||
// testlockState calls a separate process to the lock the state file at path.
|
||||
// deferFunc should be called in the caller to properly unlock the file.
|
||||
func testLockState(path string) (func(), error) {
|
||||
// Since many tests change the working durectory, the sourcedir argument must be
|
||||
// supplied to locate the statelocker.go source.
|
||||
func testLockState(sourceDir, path string) (func(), error) {
|
||||
// build and run the binary ourselves so we can quickly terminate it for cleanup
|
||||
buildDir, err := ioutil.TempDir("", "locker")
|
||||
if err != nil {
|
||||
|
@ -545,8 +547,10 @@ func testLockState(path string) (func(), error) {
|
|||
os.RemoveAll(buildDir)
|
||||
}
|
||||
|
||||
source := filepath.Join(sourceDir, "statelocker.go")
|
||||
lockBin := filepath.Join(buildDir, "statelocker")
|
||||
out, err := exec.Command("go", "build", "-o", lockBin, "testdata/statelocker.go").CombinedOutput()
|
||||
|
||||
out, err := exec.Command("go", "build", "-o", lockBin, source).CombinedOutput()
|
||||
if err != nil {
|
||||
cleanFunc()
|
||||
return nil, fmt.Errorf("%s %s", err, out)
|
||||
|
|
|
@ -46,7 +46,7 @@ func TestPlan_lockedState(t *testing.T) {
|
|||
}
|
||||
|
||||
testPath := testFixturePath("plan")
|
||||
unlock, err := testLockState(filepath.Join(testPath, DefaultStateFilename))
|
||||
unlock, err := testLockState("./testdata", filepath.Join(testPath, DefaultStateFilename))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func TestRefresh_lockedState(t *testing.T) {
|
|||
state := testState()
|
||||
statePath := testStateFile(t, state)
|
||||
|
||||
unlock, err := testLockState(statePath)
|
||||
unlock, err := testLockState("./testdata", statePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func TestTaint_lockedState(t *testing.T) {
|
|||
}
|
||||
statePath := testStateFile(t, state)
|
||||
|
||||
unlock, err := testLockState(statePath)
|
||||
unlock, err := testLockState("./testdata", statePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ func TestUntaint_lockedState(t *testing.T) {
|
|||
},
|
||||
}
|
||||
statePath := testStateFile(t, state)
|
||||
unlock, err := testLockState(statePath)
|
||||
unlock, err := testLockState("./testdata", statePath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue