Skip to content

Commit

Permalink
Fix captive core tests to write to /tmp, instead of polluting the repo
Browse files Browse the repository at this point in the history
Fixes #4290
  • Loading branch information
Paul Bellamy committed Mar 21, 2022
1 parent b4d7327 commit 460e9d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ingest/ledgerbackend/captive_core_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"}
Expand All @@ -140,6 +145,7 @@ func TestCaptiveNew(t *testing.T) {
BinaryPath: executablePath,
NetworkPassphrase: networkPassphrase,
HistoryArchiveURLs: historyURLs,
StoragePath: storagePath,
},
)

Expand Down Expand Up @@ -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
Expand All @@ -835,6 +844,7 @@ func TestCaptiveStellarCore_PrepareRangeAfterClose(t *testing.T) {
NetworkPassphrase: networkPassphrase,
HistoryArchiveURLs: historyURLs,
Toml: captiveCoreToml,
StoragePath: storagePath,
},
)
assert.NoError(t, err)
Expand Down
10 changes: 10 additions & 0 deletions ingest/ledgerbackend/file_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package ledgerbackend
import (
"context"
"fmt"
"os"
"sync"
"testing"
"time"

"github.com/stellar/go/support/log"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type mockHash struct {
Expand Down Expand Up @@ -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",
Expand All @@ -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)

Expand All @@ -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",
Expand All @@ -85,6 +94,7 @@ func TestNewFileWatcherError(t *testing.T) {
Log: log.New(),
Context: context.Background(),
Toml: captiveCoreToml,
StoragePath: storagePath,
}, stellarCoreRunnerModeOffline)
assert.NoError(t, err)

Expand Down
13 changes: 13 additions & 0 deletions ingest/ledgerbackend/stellar_core_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -20,6 +24,7 @@ func TestCloseBeforeStartOffline(t *testing.T) {
Log: log.New(),
Context: context.Background(),
Toml: captiveCoreToml,
StoragePath: storagePath,
}, stellarCoreRunnerModeOffline)
assert.NoError(t, err)

Expand All @@ -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)

Expand All @@ -47,6 +55,7 @@ func TestCloseBeforeStartOnline(t *testing.T) {
Log: log.New(),
Context: context.Background(),
Toml: captiveCoreToml,
StoragePath: storagePath,
}, stellarCoreRunnerModeOnline)
assert.NoError(t, err)

Expand All @@ -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)

Expand All @@ -73,6 +85,7 @@ func TestCloseBeforeStartOnlineWithError(t *testing.T) {
Log: log.New(),
Context: context.Background(),
Toml: captiveCoreToml,
StoragePath: storagePath,
}, stellarCoreRunnerModeOnline)
assert.NoError(t, err)

Expand Down

0 comments on commit 460e9d7

Please sign in to comment.