-
Notifications
You must be signed in to change notification settings - Fork 42
/
move_test.go
104 lines (87 loc) · 1.94 KB
/
move_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
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
package upx
import (
"fmt"
"io/ioutil"
"path"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestMove(t *testing.T) {
SetUp()
defer TearDown()
upRootPath := path.Join(ROOT, "move")
Upx("mkdir", upRootPath)
localRootPath, err := ioutil.TempDir("", "test")
assert.NoError(t, err)
localRootName := filepath.Base(localRootPath)
CreateFile(path.Join(localRootPath, "FILE1"))
CreateFile(path.Join(localRootPath, "FILE2"))
// 上传文件
Upx("put", localRootPath, upRootPath)
files, err := Ls(path.Join(upRootPath, localRootName))
assert.NoError(t, err)
assert.Len(t, files, 2)
assert.ElementsMatch(
t,
files,
[]string{"FILE1", "FILE2"},
)
time.Sleep(time.Second)
// 正常移动文件
_, err = Upx(
"mv",
path.Join(upRootPath, localRootName, "FILE1"),
path.Join(upRootPath, localRootName, "FILE3"),
)
assert.NoError(t, err)
files, err = Ls(path.Join(upRootPath, localRootName))
assert.NoError(t, err)
assert.Len(t, files, 2)
assert.ElementsMatch(
t,
files,
[]string{"FILE2", "FILE3"},
)
time.Sleep(time.Second)
// 目标文件已存在
_, err = Upx(
"mv",
path.Join(upRootPath, localRootName, "FILE2"),
path.Join(upRootPath, localRootName, "FILE3"),
)
assert.Equal(
t,
err.Error(),
fmt.Sprintf(
"target path %s already exists use -f to force overwrite\n",
path.Join(upRootPath, localRootName, "FILE3"),
),
)
files, err = Ls(path.Join(upRootPath, localRootName))
assert.NoError(t, err)
assert.Len(t, files, 2)
assert.ElementsMatch(
t,
files,
[]string{"FILE2", "FILE3"},
)
time.Sleep(time.Second)
// 目标文件已存在, 强制覆盖
_, err = Upx(
"mv",
"-f",
path.Join(upRootPath, localRootName, "FILE2"),
path.Join(upRootPath, localRootName, "FILE3"),
)
assert.NoError(t, err)
files, err = Ls(path.Join(upRootPath, localRootName))
assert.NoError(t, err)
assert.Len(t, files, 1)
assert.ElementsMatch(
t,
files,
[]string{"FILE3"},
)
}