Add mirror and cp tests
This commit is contained in:
+88
-1
@@ -16,7 +16,17 @@
|
||||
|
||||
package main
|
||||
|
||||
import . "gopkg.in/check.v1"
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
func (s *TestSuite) TestCopyURLType(c *C) {
|
||||
sourceURLs := []string{server.URL + "/bucket/object1"}
|
||||
@@ -47,3 +57,80 @@ func (s *TestSuite) TestCopyURLType(c *C) {
|
||||
targetURL = ""
|
||||
c.Assert(guessCopyURLType(sourceURLs, targetURL), Equals, copyURLsTypeInvalid)
|
||||
}
|
||||
|
||||
func (s *TestSuite) TestMirror(c *C) {
|
||||
/// filesystem
|
||||
source, err := ioutil.TempDir(os.TempDir(), "cmd-")
|
||||
c.Assert(err, IsNil)
|
||||
defer os.RemoveAll(source)
|
||||
|
||||
target, err := ioutil.TempDir(os.TempDir(), "cmd-")
|
||||
c.Assert(err, IsNil)
|
||||
defer os.RemoveAll(target)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
objectPath := filepath.Join(source, "object"+strconv.Itoa(i))
|
||||
data := "hello"
|
||||
dataLen := len(data)
|
||||
perr := putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data)))
|
||||
c.Assert(perr, IsNil)
|
||||
}
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "mirror", filepath.Join(source, "..."), target})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "mirror", filepath.Join(source, ".."), filepath.Join(target, "random")})
|
||||
c.Assert(err, IsNil)
|
||||
// in case of invalid arguments both are set
|
||||
c.Assert(console.IsError, Equals, true)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsError = false
|
||||
console.IsExited = false
|
||||
}
|
||||
|
||||
func (s *TestSuite) TestCopy(c *C) {
|
||||
/// filesystem
|
||||
source, err := ioutil.TempDir(os.TempDir(), "cmd-")
|
||||
c.Assert(err, IsNil)
|
||||
defer os.RemoveAll(source)
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
objectPath := filepath.Join(source, "object"+strconv.Itoa(i))
|
||||
data := "hello"
|
||||
dataLen := len(data)
|
||||
perr := putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data)))
|
||||
c.Assert(perr, IsNil)
|
||||
}
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
target := filepath.Join(source, "random")
|
||||
defer os.RemoveAll(target)
|
||||
|
||||
err = app.Run([]string{os.Args[0], "cp", filepath.Join(source, "..."), target})
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(console.IsExited, Equals, false)
|
||||
|
||||
// reset back
|
||||
console.IsExited = false
|
||||
|
||||
err = app.Run([]string{os.Args[0], "cp", filepath.Join(source, ".."), target})
|
||||
c.Assert(err, IsNil)
|
||||
// in case of invalid arguments both are set
|
||||
c.Assert(console.IsError, Equals, true)
|
||||
c.Assert(console.IsExited, Equals, true)
|
||||
|
||||
// reset back
|
||||
console.IsError = false
|
||||
console.IsExited = false
|
||||
}
|
||||
|
||||
+4
-2
@@ -88,8 +88,10 @@ func checkMirrorSyntax(ctx *cli.Context) {
|
||||
|
||||
_, content, err := url2Stat(tgtURL)
|
||||
fatalIf(err.Trace(tgtURL), "Unable to stat target ‘"+tgtURL+"’.")
|
||||
if !content.Type.IsDir() {
|
||||
fatalIf(errInvalidArgument().Trace(), "Target ‘"+tgtURL+"’ is not a folder.")
|
||||
if content != nil {
|
||||
if !content.Type.IsDir() {
|
||||
fatalIf(errInvalidArgument().Trace(), "Target ‘"+tgtURL+"’ is not a folder.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user