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
@@ -225,18 +235,33 @@ func (cfg *BaseNodeConfig) BaseConfig() *BaseNodeConfig {
225
235
226
236
// GenBaseDir creates a base dir that's used for the test.
227
237
func (cfg * BaseNodeConfig ) GenBaseDir () error {
228
- if cfg .BaseDir == "" {
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 == "" {
229
249
var err error
230
250
231
- // Create a temporary directory for the node's data and logs.
232
- // Use dash suffix as a separator between base name and random
233
- // suffix.
234
- dirBaseName := fmt .Sprintf ("lndtest-node-%s-" , cfg .Name )
235
251
cfg .BaseDir , err = os .MkdirTemp ("" , dirBaseName )
236
252
237
253
return err
238
254
}
239
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
+
240
265
return nil
241
266
}
242
267
0 commit comments