7
7
"os"
8
8
"path"
9
9
"path/filepath"
10
+ "time"
10
11
11
12
"github.com/btcsuite/btcd/chaincfg"
12
13
"github.com/btcsuite/btcd/integration/rpctest"
@@ -28,6 +29,10 @@ const (
28
29
)
29
30
30
31
var (
32
+ // baseDirFlag is the default directory where all the node's data are
33
+ // saved. If not set, a temporary dir will be created.
34
+ baseDirFlag = flag .String ("basedir" , "" , "default dir to save data" )
35
+
31
36
// logOutput is a flag that can be set to append the output from the
32
37
// seed nodes to log files.
33
38
logOutput = flag .Bool ("logoutput" , false ,
@@ -162,6 +167,11 @@ type BaseNodeConfig struct {
162
167
// compiled with all required itest flags.
163
168
LndBinary string
164
169
170
+ // SkipCleanup specifies whether the harness will remove the base dir or
171
+ // not when the test finishes. When using customized BaseDir, the
172
+ // cleanup will be skipped.
173
+ SkipCleanup bool
174
+
165
175
// backupDBDir is the path where a database backup is stored, if any.
166
176
backupDBDir string
167
177
@@ -223,6 +233,38 @@ func (cfg *BaseNodeConfig) BaseConfig() *BaseNodeConfig {
223
233
return cfg
224
234
}
225
235
236
+ // GenBaseDir creates a base dir that's used for the test.
237
+ func (cfg * BaseNodeConfig ) GenBaseDir () error {
238
+ // Exit early if the BaseDir is already set.
239
+ if cfg .BaseDir != "" {
240
+ return nil
241
+ }
242
+
243
+ dirBaseName := fmt .Sprintf ("itest-%v-%v-%v-%v" , cfg .LogFilenamePrefix ,
244
+ cfg .Name , cfg .NodeID , time .Now ().Unix ())
245
+
246
+ // Create a temporary directory for the node's data and logs. Use dash
247
+ // suffix as a separator between base name and node ID.
248
+ if * baseDirFlag == "" {
249
+ var err error
250
+
251
+ cfg .BaseDir , err = os .MkdirTemp ("" , dirBaseName )
252
+
253
+ return err
254
+ }
255
+
256
+ // Create the customized base dir.
257
+ if err := os .MkdirAll (* baseDirFlag , 0700 ); err != nil {
258
+ return err
259
+ }
260
+
261
+ // Use customized base dir and skip the cleanups.
262
+ cfg .BaseDir = filepath .Join (* baseDirFlag , dirBaseName )
263
+ cfg .SkipCleanup = true
264
+
265
+ return nil
266
+ }
267
+
226
268
// GenArgs generates a slice of command line arguments from the lightning node
227
269
// config struct.
228
270
func (cfg * BaseNodeConfig ) GenArgs () []string {
0 commit comments