forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_internal_test.go
More file actions
56 lines (49 loc) · 2.59 KB
/
open_internal_test.go
File metadata and controls
56 lines (49 loc) · 2.59 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
package cli
import "testing"
func Test_resolveAgentAbsPath(t *testing.T) {
t.Parallel()
type args struct {
workingDirectory string
relOrAbsPath string
agentOS string
local bool
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{"ok no args", args{}, "", false},
{"ok only working directory", args{workingDirectory: "/workdir"}, "/workdir", false},
{"ok with working directory and rel path", args{workingDirectory: "/workdir", relOrAbsPath: "my/path"}, "/workdir/my/path", false},
{"ok with working directory and abs path", args{workingDirectory: "/workdir", relOrAbsPath: "/my/path"}, "/my/path", false},
{"ok with no working directory and abs path", args{relOrAbsPath: "/my/path"}, "/my/path", false},
{"fail tilde", args{relOrAbsPath: "~"}, "", true},
{"fail tilde with working directory", args{workingDirectory: "/workdir", relOrAbsPath: "~"}, "", true},
{"fail tilde path", args{relOrAbsPath: "~/workdir"}, "", true},
{"fail tilde path with working directory", args{workingDirectory: "/workdir", relOrAbsPath: "~/workdir"}, "", true},
{"fail relative dot with no working directory", args{relOrAbsPath: "."}, "", true},
{"fail relative with no working directory", args{relOrAbsPath: "workdir"}, "", true},
{"ok with working directory and rel path on windows", args{workingDirectory: "C:\\workdir", relOrAbsPath: "my\\path", agentOS: "windows"}, "C:\\workdir\\my\\path", false},
{"ok with working directory and abs path on windows", args{workingDirectory: "C:\\workdir", relOrAbsPath: "C:\\my\\path", agentOS: "windows"}, "C:\\my\\path", false},
{"ok with no working directory and abs path on windows", args{relOrAbsPath: "C:\\my\\path", agentOS: "windows"}, "C:\\my\\path", false},
{"ok abs unix path on windows", args{workingDirectory: "C:\\workdir", relOrAbsPath: "/my/path", agentOS: "windows"}, "\\my\\path", false},
{"ok rel unix path on windows", args{workingDirectory: "C:\\workdir", relOrAbsPath: "my/path", agentOS: "windows"}, "C:\\workdir\\my\\path", false},
{"fail with no working directory and rel path on windows", args{relOrAbsPath: "my\\path", agentOS: "windows"}, "", true},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := resolveAgentAbsPath(tt.args.workingDirectory, tt.args.relOrAbsPath, tt.args.agentOS, tt.args.local)
if (err != nil) != tt.wantErr {
t.Errorf("resolveAgentAbsPath() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("resolveAgentAbsPath() = %v, want %v", got, tt.want)
}
})
}
}