-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_test.go
More file actions
119 lines (108 loc) · 2.6 KB
/
utils_test.go
File metadata and controls
119 lines (108 loc) · 2.6 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"os"
"path"
"testing"
"github.com/adrg/xdg"
"github.com/coreos/go-systemd/v22/dbus"
"github.com/stretchr/testify/assert"
)
func TestSanitizeDriveName(t *testing.T) {
for _, test := range []struct {
input string
expected string
}{
{"My Drive", "My_Drive"},
{"My/Drive", "My_Drive"},
{"My\\Drive", "My_Drive"},
{"My:Drive", "My_Drive"},
{"My?Drive", "My_Drive"},
{"My*Drive", "My_Drive"},
{"My\"Drive", "My_Drive"},
{"My<Drive", "My_Drive"},
{"My>Drive", "My_Drive"},
{"My|Drive", "My_Drive"},
{"My&Drive", "My_Drive"},
} {
result := sanitizeDriveName(test.input)
assert.Equal(t, test.expected, result)
}
}
func TestUnitNameToDriveName(t *testing.T) {
for _, test := range []struct {
input string
expected string
}{
{"rclone@mydrive.service", "mydrive"},
{"rclone@my-drive-1.service", "my-drive-1"},
{"rclone@my_drive_xyz.service", "my_drive_xyz"},
} {
result := unitNameToDriveName(test.input)
assert.Equal(t, test.expected, result)
}
}
func TestDriveNameToUnitName(t *testing.T) {
for _, test := range []struct {
input string
expected string
}{
{"mydrive", "rclone@mydrive.service"},
{"my-drive-1", "rclone@my-drive-1.service"},
{"my_drive_xyz", "rclone@my_drive_xyz.service"},
} {
result := driveNameToUnitName(test.input)
assert.Equal(t, test.expected, result)
}
}
func TestStatusesToServiceStatuses(t *testing.T) {
for _, test := range []struct {
input []dbus.UnitStatus
expected []serviceStatus
}{
{
input: []dbus.UnitStatus{
{
Name: "rclone@test.service",
Description: "Test Service",
ActiveState: "active",
},
{
Name: "rclone@my_drive.service",
Description: "My Drive Service",
ActiveState: "inactive",
},
},
expected: []serviceStatus{
{
Name: "test",
Status: "active",
MountPath: path.Join(xdg.Home, "google", "test"),
},
{
Name: "my_drive",
Status: "inactive",
MountPath: path.Join(xdg.Home, "google", "my_drive"),
},
},
},
} {
result := statusesToServiceStatuses(test.input)
assert.Equal(t, test.expected, result)
}
}
func TestEnsureFolderExists(t *testing.T) {
dir := t.TempDir()
err := os.Mkdir(path.Join(dir, "test"), 0755)
assert.NoError(t, err)
err = ensureFolderExists(path.Join(dir, "test"))
assert.NoError(t, err)
}
func TestIsDir(t *testing.T) {
dir := t.TempDir()
err := os.Mkdir(path.Join(dir, "test"), 0755)
assert.NoError(t, err)
isd := isDir(path.Join(dir, "test"))
assert.True(t, isd)
isd = isDir(path.Join(dir, "nonexistent"))
assert.False(t, isd)
}