Skip to content

Commit 60d4389

Browse files
authored
Merge pull request lightninglabs#1072 from starius/cli-tests20
cmd/loop: CLI session recording and replay tests
2 parents ea03440 + 3abede2 commit 60d4389

132 files changed

Lines changed: 15102 additions & 53 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/loop/debug.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,10 @@ func forceAutoloop(ctx context.Context, cmd *cli.Command) error {
4343
}
4444

4545
func getDebugClient(ctx context.Context, cmd *cli.Command) (looprpc.DebugClient, func(), error) {
46-
rpcServer := cmd.String("rpcserver")
47-
tlsCertPath, macaroonPath, err := extractPathArgs(cmd)
46+
conn, cleanup, err := sessionTransport.Dial(cmd)
4847
if err != nil {
4948
return nil, nil, err
5049
}
51-
conn, err := getClientConn(rpcServer, tlsCertPath, macaroonPath)
52-
if err != nil {
53-
return nil, nil, err
54-
}
55-
cleanup := func() { conn.Close() }
5650

5751
debugClient := looprpc.NewDebugClient(conn)
5852
return debugClient, cleanup, nil

cmd/loop/default_path_text_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package main
2+
3+
import (
4+
"errors"
5+
"path/filepath"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
// TestDefaultPathText verifies HOME-based path elision behavior used for help
12+
// defaults without relying on the real environment.
13+
func TestDefaultPathText(t *testing.T) {
14+
sep := string(filepath.Separator)
15+
home := filepath.Clean(sep + "home" + sep + "alice")
16+
17+
homeDir := func() (string, error) { return home, nil }
18+
19+
tests := []struct {
20+
name string
21+
value string
22+
homeFn func() (string, error)
23+
want string
24+
}{
25+
{
26+
name: "empty value",
27+
value: "",
28+
homeFn: func() (string, error) {
29+
return home, nil
30+
},
31+
want: "",
32+
},
33+
{
34+
name: "nil homedir func",
35+
value: home + sep + "data",
36+
homeFn: nil,
37+
want: home + sep + "data",
38+
},
39+
{
40+
name: "homedir error",
41+
value: home + sep + "data",
42+
homeFn: func() (string, error) {
43+
return "", errors.New("homedir error")
44+
},
45+
want: home + sep + "data",
46+
},
47+
{
48+
name: "exact home",
49+
value: home,
50+
homeFn: homeDir,
51+
want: "~",
52+
},
53+
{
54+
name: "home prefix",
55+
value: home + sep + "dir" + sep + "file",
56+
homeFn: homeDir,
57+
want: "~" + sep + "dir" + sep + "file",
58+
},
59+
{
60+
name: "non-home path",
61+
value: filepath.Clean(sep + "var" + sep + "tmp"),
62+
homeFn: homeDir,
63+
want: filepath.Clean(sep + "var" + sep + "tmp"),
64+
},
65+
{
66+
name: "prefix but not path segment",
67+
value: home + "x" + sep + "dir",
68+
homeFn: homeDir,
69+
want: home + "x" + sep + "dir",
70+
},
71+
}
72+
73+
for _, test := range tests {
74+
t.Run(test.name, func(t *testing.T) {
75+
got := defaultPathText(test.value, test.homeFn)
76+
require.Equalf(
77+
t, test.want, got,
78+
"defaultPathText(%q)", test.value,
79+
)
80+
})
81+
}
82+
}

cmd/loop/loopout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ func loopOut(ctx context.Context, cmd *cli.Command) error {
248248
// Set our maximum swap wait time. If a fast swap is requested we set
249249
// it to now, otherwise to 30 minutes in the future.
250250
fast := cmd.Bool("fast")
251-
swapDeadline := time.Now()
251+
swapDeadline := cliClock.Now()
252252
if !fast {
253-
swapDeadline = time.Now().Add(defaultSwapWaitTime)
253+
swapDeadline = cliClock.Now().Add(defaultSwapWaitTime)
254254
}
255255

256256
sweepConfTarget := int32(cmd.Uint64("conf_target"))

0 commit comments

Comments
 (0)