-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #89
- Loading branch information
Showing
7 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package upx | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"path" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCopy(t *testing.T) { | ||
SetUp() | ||
defer TearDown() | ||
|
||
upRootPath := path.Join(ROOT, "copy") | ||
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")) | ||
|
||
// 上传文件 | ||
_, err = Upx("put", localRootPath, upRootPath) | ||
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{"FILE1", "FILE2"}, | ||
) | ||
|
||
time.Sleep(time.Second) | ||
|
||
// 正常复制文件 | ||
_, err = Upx( | ||
"cp", | ||
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, 3) | ||
assert.ElementsMatch( | ||
t, | ||
files, | ||
[]string{"FILE1", "FILE2", "FILE3"}, | ||
) | ||
|
||
time.Sleep(time.Second) | ||
|
||
// 目标文件已存在 | ||
_, err = Upx( | ||
"cp", | ||
path.Join(upRootPath, localRootName, "FILE1"), | ||
path.Join(upRootPath, localRootName, "FILE2"), | ||
) | ||
assert.Error(t, err) | ||
assert.Equal( | ||
t, | ||
err.Error(), | ||
fmt.Sprintf( | ||
"target path %s already exists use -f to force overwrite\n", | ||
path.Join(upRootPath, localRootName, "FILE2"), | ||
), | ||
) | ||
|
||
files, err = Ls(path.Join(upRootPath, localRootName)) | ||
assert.NoError(t, err) | ||
assert.Len(t, files, 3) | ||
assert.ElementsMatch( | ||
t, | ||
files, | ||
[]string{"FILE1", "FILE2", "FILE3"}, | ||
) | ||
|
||
time.Sleep(time.Second) | ||
|
||
// 目标文件已存在, 强制覆盖 | ||
_, err = Upx( | ||
"cp", | ||
"-f", | ||
path.Join(upRootPath, localRootName, "FILE1"), | ||
path.Join(upRootPath, localRootName, "FILE2"), | ||
) | ||
assert.NoError(t, err) | ||
|
||
files, err = Ls(path.Join(upRootPath, localRootName)) | ||
assert.NoError(t, err) | ||
assert.Len(t, files, 3) | ||
assert.ElementsMatch( | ||
t, | ||
files, | ||
[]string{"FILE1", "FILE2", "FILE3"}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.