Skip to content
Open
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
8 changes: 1 addition & 7 deletions cmd/loop/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,10 @@ func forceAutoloop(ctx context.Context, cmd *cli.Command) error {
}

func getDebugClient(ctx context.Context, cmd *cli.Command) (looprpc.DebugClient, func(), error) {
rpcServer := cmd.String("rpcserver")
tlsCertPath, macaroonPath, err := extractPathArgs(cmd)
conn, cleanup, err := sessionTransport.Dial(cmd)
if err != nil {
return nil, nil, err
}
conn, err := getClientConn(rpcServer, tlsCertPath, macaroonPath)
if err != nil {
return nil, nil, err
}
cleanup := func() { conn.Close() }

debugClient := looprpc.NewDebugClient(conn)
return debugClient, cleanup, nil
Expand Down
82 changes: 82 additions & 0 deletions cmd/loop/default_path_text_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package main

import (
"errors"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

// TestDefaultPathText verifies HOME-based path elision behavior used for help
// defaults without relying on the real environment.
func TestDefaultPathText(t *testing.T) {
sep := string(filepath.Separator)
home := filepath.Clean(sep + "home" + sep + "alice")

homeDir := func() (string, error) { return home, nil }

tests := []struct {
name string
value string
homeFn func() (string, error)
want string
}{
{
name: "empty value",
value: "",
homeFn: func() (string, error) {
return home, nil
},
want: "",
},
{
name: "nil homedir func",
value: home + sep + "data",
homeFn: nil,
want: home + sep + "data",
},
{
name: "homedir error",
value: home + sep + "data",
homeFn: func() (string, error) {
return "", errors.New("homedir error")
},
want: home + sep + "data",
},
{
name: "exact home",
value: home,
homeFn: homeDir,
want: "~",
},
{
name: "home prefix",
value: home + sep + "dir" + sep + "file",
homeFn: homeDir,
want: "~" + sep + "dir" + sep + "file",
},
{
name: "non-home path",
value: filepath.Clean(sep + "var" + sep + "tmp"),
homeFn: homeDir,
want: filepath.Clean(sep + "var" + sep + "tmp"),
},
{
name: "prefix but not path segment",
value: home + "x" + sep + "dir",
homeFn: homeDir,
want: home + "x" + sep + "dir",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := defaultPathText(test.value, test.homeFn)
require.Equalf(
t, test.want, got,
"defaultPathText(%q)", test.value,
)
})
}
}
4 changes: 2 additions & 2 deletions cmd/loop/loopout.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ func loopOut(ctx context.Context, cmd *cli.Command) error {
// Set our maximum swap wait time. If a fast swap is requested we set
// it to now, otherwise to 30 minutes in the future.
fast := cmd.Bool("fast")
swapDeadline := time.Now()
swapDeadline := cliClock.Now()
if !fast {
swapDeadline = time.Now().Add(defaultSwapWaitTime)
swapDeadline = cliClock.Now().Add(defaultSwapWaitTime)
}

sweepConfTarget := int32(cmd.Uint64("conf_target"))
Expand Down
Loading
Loading