From 460e9d76e8792337a7197bc95c3c2a902df48e0f Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 21 Mar 2022 13:44:54 +0000 Subject: [PATCH] Fix captive core tests to write to /tmp, instead of polluting the repo Fixes #4290 --- ingest/ledgerbackend/captive_core_backend_test.go | 10 ++++++++++ ingest/ledgerbackend/file_watcher_test.go | 10 ++++++++++ ingest/ledgerbackend/stellar_core_runner_test.go | 13 +++++++++++++ 3 files changed, 33 insertions(+) diff --git a/ingest/ledgerbackend/captive_core_backend_test.go b/ingest/ledgerbackend/captive_core_backend_test.go index f73341370f..481a1e3c1d 100644 --- a/ingest/ledgerbackend/captive_core_backend_test.go +++ b/ingest/ledgerbackend/captive_core_backend_test.go @@ -4,10 +4,12 @@ import ( "context" "encoding/hex" "fmt" + "os" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "github.com/stellar/go/historyarchive" "github.com/stellar/go/network" @@ -131,6 +133,9 @@ type testLedgerHeader struct { } func TestCaptiveNew(t *testing.T) { + storagePath, err := os.MkdirTemp(os.TempDir(), "captive-core-*") + require.NoError(t, err) + executablePath := "/etc/stellar-core" networkPassphrase := network.PublicNetworkPassphrase historyURLs := []string{"http://history.stellar.org/prd/core-live/core_live_001"} @@ -140,6 +145,7 @@ func TestCaptiveNew(t *testing.T) { BinaryPath: executablePath, NetworkPassphrase: networkPassphrase, HistoryArchiveURLs: historyURLs, + StoragePath: storagePath, }, ) @@ -821,6 +827,9 @@ func TestCaptiveGetLedger_NextLedger0RangeFromIsSmallerThanLedgerFromBuffer(t *t } func TestCaptiveStellarCore_PrepareRangeAfterClose(t *testing.T) { + storagePath, err := os.MkdirTemp(os.TempDir(), "captive-core-*") + require.NoError(t, err) + ctx := context.Background() executablePath := "/etc/stellar-core" networkPassphrase := network.PublicNetworkPassphrase @@ -835,6 +844,7 @@ func TestCaptiveStellarCore_PrepareRangeAfterClose(t *testing.T) { NetworkPassphrase: networkPassphrase, HistoryArchiveURLs: historyURLs, Toml: captiveCoreToml, + StoragePath: storagePath, }, ) assert.NoError(t, err) diff --git a/ingest/ledgerbackend/file_watcher_test.go b/ingest/ledgerbackend/file_watcher_test.go index e46606d2e8..ed5d4a3fc7 100644 --- a/ingest/ledgerbackend/file_watcher_test.go +++ b/ingest/ledgerbackend/file_watcher_test.go @@ -3,6 +3,7 @@ package ledgerbackend import ( "context" "fmt" + "os" "sync" "testing" "time" @@ -10,6 +11,7 @@ import ( "github.com/stellar/go/support/log" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type mockHash struct { @@ -43,6 +45,9 @@ func (m *mockHash) hashFile(fp string) (hash, error) { } func createFWFixtures(t *testing.T) (*mockHash, *stellarCoreRunner, *fileWatcher) { + storagePath, err := os.MkdirTemp(os.TempDir(), "captive-core-*") + require.NoError(t, err) + ms := &mockHash{ hashResult: hash{}, expectedPath: "/some/path", @@ -58,6 +63,7 @@ func createFWFixtures(t *testing.T) (*mockHash, *stellarCoreRunner, *fileWatcher Log: log.New(), Context: context.Background(), Toml: captiveCoreToml, + StoragePath: storagePath, }, stellarCoreRunnerModeOffline) assert.NoError(t, err) @@ -69,6 +75,9 @@ func createFWFixtures(t *testing.T) (*mockHash, *stellarCoreRunner, *fileWatcher } func TestNewFileWatcherError(t *testing.T) { + storagePath, err := os.MkdirTemp(os.TempDir(), "captive-core-*") + require.NoError(t, err) + ms := &mockHash{ hashResult: hash{}, expectedPath: "/some/path", @@ -85,6 +94,7 @@ func TestNewFileWatcherError(t *testing.T) { Log: log.New(), Context: context.Background(), Toml: captiveCoreToml, + StoragePath: storagePath, }, stellarCoreRunnerModeOffline) assert.NoError(t, err) diff --git a/ingest/ledgerbackend/stellar_core_runner_test.go b/ingest/ledgerbackend/stellar_core_runner_test.go index 18e6b0656a..5b7a12a5a2 100644 --- a/ingest/ledgerbackend/stellar_core_runner_test.go +++ b/ingest/ledgerbackend/stellar_core_runner_test.go @@ -7,11 +7,15 @@ import ( "github.com/pkg/errors" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/stellar/go/support/log" ) func TestCloseBeforeStartOffline(t *testing.T) { + storagePath, err := os.MkdirTemp(os.TempDir(), "captive-core-*") + require.NoError(t, err) + captiveCoreToml, err := NewCaptiveCoreToml(CaptiveCoreTomlParams{}) assert.NoError(t, err) @@ -20,6 +24,7 @@ func TestCloseBeforeStartOffline(t *testing.T) { Log: log.New(), Context: context.Background(), Toml: captiveCoreToml, + StoragePath: storagePath, }, stellarCoreRunnerModeOffline) assert.NoError(t, err) @@ -37,6 +42,9 @@ func TestCloseBeforeStartOffline(t *testing.T) { } func TestCloseBeforeStartOnline(t *testing.T) { + storagePath, err := os.MkdirTemp(os.TempDir(), "captive-core-*") + require.NoError(t, err) + captiveCoreToml, err := NewCaptiveCoreToml(CaptiveCoreTomlParams{}) assert.NoError(t, err) @@ -47,6 +55,7 @@ func TestCloseBeforeStartOnline(t *testing.T) { Log: log.New(), Context: context.Background(), Toml: captiveCoreToml, + StoragePath: storagePath, }, stellarCoreRunnerModeOnline) assert.NoError(t, err) @@ -63,6 +72,9 @@ func TestCloseBeforeStartOnline(t *testing.T) { } func TestCloseBeforeStartOnlineWithError(t *testing.T) { + storagePath, err := os.MkdirTemp(os.TempDir(), "captive-core-*") + require.NoError(t, err) + captiveCoreToml, err := NewCaptiveCoreToml(CaptiveCoreTomlParams{}) assert.NoError(t, err) @@ -73,6 +85,7 @@ func TestCloseBeforeStartOnlineWithError(t *testing.T) { Log: log.New(), Context: context.Background(), Toml: captiveCoreToml, + StoragePath: storagePath, }, stellarCoreRunnerModeOnline) assert.NoError(t, err)