-
Notifications
You must be signed in to change notification settings - Fork 125
/
file_util_test.go
67 lines (60 loc) · 1.3 KB
/
file_util_test.go
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
package gosnowflake
import (
"os/user"
"path/filepath"
"testing"
)
func TestGetDigestAndSizeForInvalidDir(t *testing.T) {
fileUtil := new(snowflakeFileUtil)
digest, size, err := fileUtil.getDigestAndSizeForFile("/home/file.txt")
if digest != "" {
t.Fatal("should be empty")
}
if size != 0 {
t.Fatal("should be 0")
}
if err == nil {
t.Fatal("should have failed")
}
}
type tcBaseName struct {
in string
out string
}
func TestBaseName(t *testing.T) {
testcases := []tcBaseName{
{"/tmp", "tmp"},
{"/home/desktop/.", ""},
{"/home/desktop/..", ""},
}
for _, test := range testcases {
t.Run(test.in, func(t *testing.T) {
base := baseName(test.in)
if test.out != base {
t.Errorf("Failed to get base, input %v, expected: %v, got: %v", test.in, test.out, base)
}
})
}
}
func TestExpandUser(t *testing.T) {
usr, err := user.Current()
if err != nil {
t.Fatal(err)
}
homeDir := usr.HomeDir
user, err := expandUser("~")
if err != nil {
t.Fatal(err)
}
if homeDir != user {
t.Fatalf("failed to expand user, expected: %v, got: %v", homeDir, user)
}
user, err = expandUser("~/storage")
if err != nil {
t.Fatal(err)
}
expectedPath := filepath.Join(homeDir, "storage")
if expectedPath != user {
t.Fatalf("failed to expand user, expected: %v, got: %v", expectedPath, user)
}
}