Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon: Fix captive core tests to write to /tmp, instead of polluting the repo #4296

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-*")
Copy link
Member

@leighmcculloch leighmcculloch Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fyi if you use the empty string it will use the temp for by default. The first param is optional.

Suggested change
storagePath, err := os.MkdirTemp(os.TempDir(), "captive-core-*")
storagePath, err := os.MkdirTemp("", "captive-core-*")

require.NoError(t, err)
Copy link
Member

@leighmcculloch leighmcculloch Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a defer to remove the directory after the test finishes? Or does that compromise the ability to debug failing tests?


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