-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
61 lines (58 loc) · 1.68 KB
/
Copy pathmain_test.go
File metadata and controls
61 lines (58 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"os"
"os/user"
"testing"
"github.com/zk-org/zk/internal/cli"
)
func Test_parseDirsPathExpansion(t *testing.T) {
user, _ := user.Current()
_ = os.Setenv("FOO", "/home/foo")
tests := []struct {
name string
args []string
wantDirs cli.Dirs
}{
{
name: "With tilde (working dir)",
args: []string{"--working-dir=~/notes"},
wantDirs: cli.Dirs{WorkingDir: user.HomeDir + "/notes"},
},
{
name: "With tilde (notebook dir)",
args: []string{"--notebook-dir=~/notes"},
wantDirs: cli.Dirs{NotebookDir: user.HomeDir + "/notes"},
},
{
name: "With absolute path",
args: []string{"--notebook-dir=" + user.HomeDir + "/notes"},
wantDirs: cli.Dirs{NotebookDir: user.HomeDir + "/notes"},
},
{
name: "With environment variable in path",
args: []string{"--notebook-dir=${FOO}/notes"},
wantDirs: cli.Dirs{NotebookDir: os.Getenv("FOO") + "/notes"},
},
{
name: "With environment variable and two string argument",
args: []string{"--notebook-dir", "${FOO}/notes"},
wantDirs: cli.Dirs{NotebookDir: os.Getenv("FOO") + "/notes"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cliDirs, _, gotErr := parseDirs(tt.args)
workDir := cliDirs.WorkingDir
noteDir := cliDirs.NotebookDir
if gotErr != nil {
t.Errorf("parseDirs() failed: %v", gotErr)
}
if workDir != tt.wantDirs.WorkingDir {
t.Errorf("parseDirs() got WorkingDir = %v, want %v", cliDirs.WorkingDir, tt.wantDirs.WorkingDir)
}
if noteDir != tt.wantDirs.NotebookDir {
t.Errorf("parseDirs() got NotebookDir = %v, want %v", cliDirs.NotebookDir, tt.wantDirs.NotebookDir)
}
})
}
}