Просмотр исходного кода

Avoid file migrations writing to test current working dir

Rod Hynes 6 лет назад
Родитель
Сommit
308a5214cb
2 измененных файлов с 30 добавлено и 6 удалено
  1. 8 1
      psiphon/config_test.go
  2. 22 5
      psiphon/server/server_test.go

+ 8 - 1
psiphon/config_test.go

@@ -21,6 +21,7 @@ package psiphon
 
 import (
 	"encoding/json"
+	"fmt"
 	"io/ioutil"
 	"os"
 	"path/filepath"
@@ -120,7 +121,13 @@ func (suite *ConfigTestSuite) Test_LoadConfig_BadJson() {
 	var testObjJSON []byte
 
 	// JSON with none of our fields
-	config, err := LoadConfig([]byte(`{"f1": 11, "f2": "two"}`))
+	//
+	// DataRootDirectory must to be set to avoid a migration in the current
+	// working directory.
+	config, err := LoadConfig([]byte(
+		fmt.Sprintf(
+			`{"f1": 11, "f2": "two", "DataRootDirectory" : %s}`,
+			suite.testDirectory)))
 	if err == nil {
 		err = config.Commit()
 	}

+ 22 - 5
psiphon/server/server_test.go

@@ -833,7 +833,7 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
 		t.Fatalf("error processing configuration file: %s", err)
 	}
 
-	clientConfig.DataStoreDirectory = testDataDirName
+	clientConfig.DataRootDirectory = testDataDirName
 
 	if !runConfig.doDefaultSponsorID {
 		clientConfig.SponsorId = sponsorID
@@ -914,7 +914,8 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
 	psiphon.DeleteSLOKs()
 
 	// Store prune server entry test server entries and failed tunnel records.
-	storePruneServerEntriesTest(t, runConfig, pruneServerEntryTestCases)
+	storePruneServerEntriesTest(
+		t, runConfig, testDataDirName, pruneServerEntryTestCases)
 
 	controller, err := psiphon.NewController(clientConfig)
 	if err != nil {
@@ -1139,7 +1140,7 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
 	}
 
 	// Check that datastore had retained/pruned server entries as expected.
-	checkPruneServerEntriesTest(t, runConfig, pruneServerEntryTestCases)
+	checkPruneServerEntriesTest(t, runConfig, testDataDirName, pruneServerEntryTestCases)
 }
 
 func checkExpectedLogFields(runConfig *runServerConfig, fields map[string]interface{}) error {
@@ -1995,6 +1996,7 @@ func initializePruneServerEntriesTest(
 func storePruneServerEntriesTest(
 	t *testing.T,
 	runConfig *runServerConfig,
+	testDataDirName string,
 	pruneServerEntryTestCases []*pruneServerEntryTestCase) {
 
 	if !runConfig.doPruneServerEntries {
@@ -2009,7 +2011,14 @@ func storePruneServerEntriesTest(
 		}
 	}
 
-	clientConfig := &psiphon.Config{SponsorId: "0", PropagationChannelId: "0"}
+	clientConfig := &psiphon.Config{
+		SponsorId:            "0",
+		PropagationChannelId: "0",
+
+		// DataRootDirectory must to be set to avoid a migration in the current
+		// working directory.
+		DataRootDirectory: testDataDirName,
+	}
 	err := clientConfig.Commit()
 	if err != nil {
 		t.Fatalf("Commit failed: %s", err)
@@ -2072,13 +2081,21 @@ func storePruneServerEntriesTest(
 func checkPruneServerEntriesTest(
 	t *testing.T,
 	runConfig *runServerConfig,
+	testDataDirName string,
 	pruneServerEntryTestCases []*pruneServerEntryTestCase) {
 
 	if !runConfig.doPruneServerEntries {
 		return
 	}
 
-	clientConfig := &psiphon.Config{SponsorId: "0", PropagationChannelId: "0"}
+	clientConfig := &psiphon.Config{
+		SponsorId:            "0",
+		PropagationChannelId: "0",
+
+		// DataRootDirectory must to be set to avoid a migration in the current
+		// working directory.
+		DataRootDirectory: testDataDirName,
+	}
 	err := clientConfig.Commit()
 	if err != nil {
 		t.Fatalf("Commit failed: %s", err)