lntest: add a new basedir flag to keep test data
This commit is contained in:
2 files changed
+37
-5
No files matched your search
+30
-5
@@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/integration/rpctest"
|
"github.com/btcsuite/btcd/integration/rpctest"
|
||||||
@@ -28,6 +29,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// baseDirFlag is the default directory where all the node's data are
|
||||||
|
// saved. If not set, a temporary dir will be created.
|
||||||
|
baseDirFlag = flag.String("basedir", "", "default dir to save data")
|
||||||
|
|
||||||
// logOutput is a flag that can be set to append the output from the
|
// logOutput is a flag that can be set to append the output from the
|
||||||
// seed nodes to log files.
|
// seed nodes to log files.
|
||||||
logOutput = flag.Bool("logoutput", false,
|
logOutput = flag.Bool("logoutput", false,
|
||||||
@@ -162,6 +167,11 @@ type BaseNodeConfig struct {
|
|||||||
// compiled with all required itest flags.
|
// compiled with all required itest flags.
|
||||||
LndBinary string
|
LndBinary string
|
||||||
|
|
||||||
|
// SkipCleanup specifies whether the harness will remove the base dir or
|
||||||
|
// not when the test finishes. When using customized BaseDir, the
|
||||||
|
// cleanup will be skipped.
|
||||||
|
SkipCleanup bool
|
||||||
|
|
||||||
// backupDBDir is the path where a database backup is stored, if any.
|
// backupDBDir is the path where a database backup is stored, if any.
|
||||||
backupDBDir string
|
backupDBDir string
|
||||||
|
|
||||||
@@ -225,18 +235,33 @@ func (cfg *BaseNodeConfig) BaseConfig() *BaseNodeConfig {
|
|||||||
|
|
||||||
// GenBaseDir creates a base dir that's used for the test.
|
// GenBaseDir creates a base dir that's used for the test.
|
||||||
func (cfg *BaseNodeConfig) GenBaseDir() error {
|
func (cfg *BaseNodeConfig) GenBaseDir() error {
|
||||||
if cfg.BaseDir == "" {
|
// Exit early if the BaseDir is already set.
|
||||||
|
if cfg.BaseDir != "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
dirBaseName := fmt.Sprintf("itest-%v-%v-%v-%v", cfg.LogFilenamePrefix,
|
||||||
|
cfg.Name, cfg.NodeID, time.Now().Unix())
|
||||||
|
|
||||||
|
// Create a temporary directory for the node's data and logs. Use dash
|
||||||
|
// suffix as a separator between base name and node ID.
|
||||||
|
if *baseDirFlag == "" {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Create a temporary directory for the node's data and logs.
|
|
||||||
// Use dash suffix as a separator between base name and random
|
|
||||||
// suffix.
|
|
||||||
dirBaseName := fmt.Sprintf("lndtest-node-%s-", cfg.Name)
|
|
||||||
cfg.BaseDir, err = os.MkdirTemp("", dirBaseName)
|
cfg.BaseDir, err = os.MkdirTemp("", dirBaseName)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the customized base dir.
|
||||||
|
if err := os.MkdirAll(*baseDirFlag, 0700); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use customized base dir and skip the cleanups.
|
||||||
|
cfg.BaseDir = filepath.Join(*baseDirFlag, dirBaseName)
|
||||||
|
cfg.SkipCleanup = true
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -794,6 +794,13 @@ func (hn *HarnessNode) Shutdown() error {
|
|||||||
if err := hn.Stop(); err != nil {
|
if err := hn.Stop(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit if we want to skip the cleanup, which happens when a customized
|
||||||
|
// base dir is used.
|
||||||
|
if hn.Cfg.SkipCleanup {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := hn.cleanup(); err != nil {
|
if err := hn.cleanup(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user