diff --git a/cat_test.go b/cat_test.go index 82249126..0f2db0bf 100644 --- a/cat_test.go +++ b/cat_test.go @@ -27,7 +27,7 @@ import ( . "gopkg.in/check.v1" ) -func (s *CmdTestSuite) TestCatCmd(c *C) { +func (s *TestSuite) TestCat(c *C) { /// filesystem root, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) @@ -55,7 +55,7 @@ func (s *CmdTestSuite) TestCatCmd(c *C) { c.Assert(catURL(objectPath), Not(IsNil)) } -func (s *CmdTestSuite) TestCatContext(c *C) { +func (s *TestSuite) TestCatContext(c *C) { err := app.Run([]string{os.Args[0], "cat", server.URL + "/bucket/object1"}) c.Assert(err, IsNil) c.Assert(console.IsExited, Equals, false) diff --git a/common_methods_test.go b/common_methods_test.go index a5be5e3a..1c3bd6c8 100644 --- a/common_methods_test.go +++ b/common_methods_test.go @@ -26,7 +26,7 @@ import ( . "gopkg.in/check.v1" ) -func (s *CmdTestSuite) TestCommonMethods(c *C) { +func (s *TestSuite) TestCommonMethods(c *C) { /// filesystem root, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) diff --git a/config_test.go b/config_test.go index 6204eefd..15f38cec 100644 --- a/config_test.go +++ b/config_test.go @@ -23,7 +23,7 @@ import ( . "gopkg.in/check.v1" ) -func (s *CmdTestSuite) TestConfigAliasContext(c *C) { +func (s *TestSuite) TestConfigAliasContext(c *C) { console.IsExited = false err := app.Run([]string{os.Args[0], "config", "alias", "add", "test", "htt://test.io"}) @@ -41,7 +41,7 @@ func (s *CmdTestSuite) TestConfigAliasContext(c *C) { console.IsExited = false } -func (s *CmdTestSuite) TestConfigHostContext(c *C) { +func (s *TestSuite) TestConfigHostContext(c *C) { console.IsExited = false err := app.Run([]string{os.Args[0], "config", "host", "add", "*test.io", "invalid", "invalid"}) diff --git a/cp_mirror_test.go b/cp_mirror_test.go index ae81dd22..8fda8d27 100644 --- a/cp_mirror_test.go +++ b/cp_mirror_test.go @@ -23,7 +23,7 @@ import ( . "gopkg.in/check.v1" ) -func (s *CmdTestSuite) TestCopyURLType(c *C) { +func (s *TestSuite) TestCopyURLType(c *C) { sourceURLs := []string{server.URL + "/bucket/object1"} targetURL := server.URL + "/bucket/test" c.Assert(guessCopyURLType(sourceURLs, targetURL), Equals, copyURLsTypeA) @@ -53,8 +53,7 @@ func (s *CmdTestSuite) TestCopyURLType(c *C) { c.Assert(guessCopyURLType(sourceURLs, targetURL), Equals, copyURLsTypeInvalid) } -// TODO fix both copy and mirror -func (s *CmdTestSuite) TestCopyContext(c *C) { +func (s *TestSuite) TestCopyContext(c *C) { err := app.Run([]string{os.Args[0], "cp", server.URL + "/invalid...", server.URL + "/bucket"}) c.Assert(err, IsNil) c.Assert(console.IsError, Equals, true) @@ -63,7 +62,7 @@ func (s *CmdTestSuite) TestCopyContext(c *C) { console.IsError = false } -func (s *CmdTestSuite) TestMirrorContext(c *C) { +func (s *TestSuite) TestMirrorContext(c *C) { err := app.Run([]string{os.Args[0], "mirror", server.URL + "/invalid...", server.URL + "/bucket"}) c.Assert(err, IsNil) c.Assert(console.IsError, Equals, true) diff --git a/diff-main.go b/diff-main.go index d302f3fa..90a03c87 100644 --- a/diff-main.go +++ b/diff-main.go @@ -78,15 +78,15 @@ func mainDiff(ctx *cli.Context) { secondURL := getAliasURL(secondArg, config.Aliases) newFirstURL := stripRecursiveURL(firstURL) - for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) { + for diff := range doDiff(newFirstURL, secondURL, isURLRecursive(firstURL)) { fatalIf(diff.Error.Trace(newFirstURL, secondURL), "Failed to diff ‘"+firstURL+"’ and ‘"+secondURL+"’.") Prints("%s\n", diff) } } -// doDiffCmd - Execute the diff command -func doDiffCmd(firstURL, secondURL string, recursive bool) <-chan DiffMessage { +// doDiff - Execute the diff command +func doDiff(firstURL, secondURL string, recursive bool) <-chan DiffMessage { ch := make(chan DiffMessage, 10000) go doDiffInRoutine(firstURL, secondURL, recursive, ch) return ch diff --git a/diff_test.go b/diff_test.go index fab5f4f3..e4bab3e3 100644 --- a/diff_test.go +++ b/diff_test.go @@ -28,7 +28,7 @@ import ( . "gopkg.in/check.v1" ) -func (s *CmdTestSuite) TestDiffObjects(c *C) { +func (s *TestSuite) TestDiffObjects(c *C) { /// filesystem root1, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) @@ -50,12 +50,12 @@ func (s *CmdTestSuite) TestDiffObjects(c *C) { perr = putTarget(objectPath2, int64(dataLen), bytes.NewReader([]byte(data))) c.Assert(perr, IsNil) - for diff := range doDiffCmd(objectPath1, objectPath2, false) { + for diff := range doDiff(objectPath1, objectPath2, false) { c.Assert(diff.Error, IsNil) } } -func (s *CmdTestSuite) TestDiffDirs(c *C) { +func (s *TestSuite) TestDiffDirs(c *C) { /// filesystem root1, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) @@ -82,12 +82,12 @@ func (s *CmdTestSuite) TestDiffDirs(c *C) { c.Assert(perr, IsNil) } - for diff := range doDiffCmd(root1, root2, false) { + for diff := range doDiff(root1, root2, false) { c.Assert(diff.Error, IsNil) } } -func (s *CmdTestSuite) TestDiffContext(c *C) { +func (s *TestSuite) TestDiffContext(c *C) { err := app.Run([]string{os.Args[0], "diff", server.URL + "/bucket", server.URL + "/bucket"}) c.Assert(err, IsNil) c.Assert(console.IsExited, Equals, false) diff --git a/error.go b/error.go index 17da5ed6..87ec6bfc 100644 --- a/error.go +++ b/error.go @@ -19,7 +19,6 @@ package main import ( "encoding/json" "fmt" - "os" "github.com/minio/mc/pkg/console" "github.com/minio/minio/pkg/probe" @@ -58,7 +57,7 @@ func fatalIf(err *probe.Error, msg string) { console.Fatalln(probe.NewError(err)) } console.Println(string(json)) - os.Exit(1) + console.Fatal("") } if !globalDebugFlag { console.Fatalln(fmt.Sprintf("%s %s", msg, err.ToGoError())) @@ -90,6 +89,7 @@ func errorIf(err *probe.Error, msg string) { console.Fatalln(probe.NewError(err)) } console.Println(string(json)) + console.Error("") return } if !globalDebugFlag { diff --git a/ls.go b/ls.go index 624479ab..9ddb9859 100644 --- a/ls.go +++ b/ls.go @@ -104,13 +104,12 @@ func parseContent(c *client.Content) ContentMessage { // doList - list all entities inside a folder. func doList(clnt client.Client, recursive, lsPrefixMode bool) *probe.Error { - var err *probe.Error parentContent, err := clnt.Stat() if err != nil { return err.Trace(clnt.URL().String()) } if parentContent.Type.IsDir() && lsPrefixMode { - console.Println(console.Colorize("Dir", fmt.Sprintf("%s", clnt.URL().String()))) + console.Println(console.Colorize("Dir", fmt.Sprintf("%s:", clnt.URL().String()))) } for contentCh := range clnt.List(recursive) { if contentCh.Err != nil { @@ -132,6 +131,9 @@ func doList(clnt client.Client, recursive, lsPrefixMode bool) *probe.Error { err = contentCh.Err.Trace() break } + if parentContent.Type.IsRegular() && lsPrefixMode { + console.Println("") + } Prints("%s\n", parseContent(contentCh.Content)) } if err != nil { diff --git a/ls_test.go b/ls_test.go index 640d1571..10c7dd2f 100644 --- a/ls_test.go +++ b/ls_test.go @@ -23,12 +23,13 @@ import ( "path/filepath" "strconv" + "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/console" "github.com/minio/minio/pkg/probe" . "gopkg.in/check.v1" ) -func (s *CmdTestSuite) TestLSCmd(c *C) { +func (s *TestSuite) TestLS(c *C) { /// filesystem root, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) @@ -44,10 +45,14 @@ func (s *CmdTestSuite) TestLSCmd(c *C) { c.Assert(perr, IsNil) } - perr = doListCmd(root, false) + var clnt client.Client + clnt, perr = target2Client(root) c.Assert(perr, IsNil) - perr = doListCmd(root, true) + perr = doList(clnt, false, false) + c.Assert(perr, IsNil) + + perr = doList(clnt, true, false) c.Assert(perr, IsNil) for i := 0; i < 10; i++ { @@ -57,14 +62,18 @@ func (s *CmdTestSuite) TestLSCmd(c *C) { perr := putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) c.Assert(perr, IsNil) } - perr = doListCmd(server.URL+"/bucket", false) + + clnt, perr = target2Client(server.URL + "/bucket") c.Assert(perr, IsNil) - perr = doListCmd(server.URL+"/bucket", true) + perr = doList(clnt, false, false) + c.Assert(perr, IsNil) + + perr = doList(clnt, true, false) c.Assert(perr, IsNil) } -func (s *CmdTestSuite) TestLSContext(c *C) { +func (s *TestSuite) TestLSContext(c *C) { err := app.Run([]string{os.Args[0], "ls", server.URL + "/bucket"}) c.Assert(err, IsNil) c.Assert(console.IsError, Equals, false) diff --git a/mb-main.go b/mb-main.go index 73b75c12..59f9f094 100644 --- a/mb-main.go +++ b/mb-main.go @@ -91,7 +91,7 @@ func mainMakeBucket(ctx *cli.Context) { for _, arg := range ctx.Args() { targetURL := getAliasURL(arg, config.Aliases) - fatalIf(doMakeBucketCmd(targetURL).Trace(targetURL), "Unable to make bucket ‘"+targetURL+"’.") + fatalIf(doMakeBucket(targetURL).Trace(targetURL), "Unable to make bucket ‘"+targetURL+"’.") Prints("%s\n", MakeBucketMessage{ Status: "success", Bucket: targetURL, @@ -99,8 +99,8 @@ func mainMakeBucket(ctx *cli.Context) { } } -// doMakeBucketCmd - -func doMakeBucketCmd(targetURL string) *probe.Error { +// doMakeBucket - +func doMakeBucket(targetURL string) *probe.Error { clnt, err := target2Client(targetURL) if err != nil { return err.Trace(targetURL) diff --git a/mb_access_test.go b/mb_access_test.go index 76b0eaa7..ff235917 100644 --- a/mb_access_test.go +++ b/mb_access_test.go @@ -23,8 +23,8 @@ import ( . "gopkg.in/check.v1" ) -func (s *CmdTestSuite) TestMbAndAccessCmd(c *C) { - perr := doMakeBucketCmd(server.URL + "/bucket") +func (s *TestSuite) TestMbAndAccess(c *C) { + perr := doMakeBucket(server.URL + "/bucket") c.Assert(perr, IsNil) perr = doSetAccess(server.URL+"/bucket", "public-read-write") @@ -34,7 +34,7 @@ func (s *CmdTestSuite) TestMbAndAccessCmd(c *C) { c.Assert(perr, Not(IsNil)) } -func (s *CmdTestSuite) TestMBContext(c *C) { +func (s *TestSuite) TestMBContext(c *C) { console.IsExited = false err := app.Run([]string{os.Args[0], "mb", server.URL + "/bucket"}) @@ -52,7 +52,7 @@ func (s *CmdTestSuite) TestMBContext(c *C) { console.IsExited = false } -func (s *CmdTestSuite) TestAccessContext(c *C) { +func (s *TestSuite) TestAccessContext(c *C) { console.IsExited = false err := app.Run([]string{os.Args[0], "access", "set", "private", server.URL + "/bucket"}) diff --git a/cmd_test.go b/mc_test.go similarity index 88% rename from cmd_test.go rename to mc_test.go index 2103113f..a394f6dc 100644 --- a/cmd_test.go +++ b/mc_test.go @@ -36,20 +36,22 @@ var customConfigDir string func Test(t *testing.T) { TestingT(t) } -type CmdTestSuite struct{} +type TestSuite struct{} -var _ = Suite(&CmdTestSuite{}) +var _ = Suite(&TestSuite{}) var server *httptest.Server var app *cli.App -func (s *CmdTestSuite) SetUpSuite(c *C) { +func (s *TestSuite) SetUpSuite(c *C) { objectAPI := objectAPIHandler(objectAPIHandler{lock: &sync.Mutex{}, bucket: "bucket", object: make(map[string][]byte)}) server = httptest.NewServer(objectAPI) console.IsTesting = true // do not set it elsewhere, leads to data races since this is a global flag - globalQuietFlag = true + globalQuietFlag = true // quiet is set to turn of progress bar + // do not set it elsewhere, leads to data races since this is a global flag + globalJSONFlag = true // json is set to avoid printing colors upon terminals tmpDir, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) @@ -77,14 +79,14 @@ func (s *CmdTestSuite) SetUpSuite(c *C) { app = registerApp() } -func (s *CmdTestSuite) TearDownSuite(c *C) { +func (s *TestSuite) TearDownSuite(c *C) { os.RemoveAll(customConfigDir) if server != nil { server.Close() } } -func (s *CmdTestSuite) TestGetNewClient(c *C) { +func (s *TestSuite) TestGetNewClient(c *C) { _, err := getNewClient("http://example.com/bucket1", hostConfig{}) c.Assert(err, IsNil) _, err = getNewClient("https://example.com/bucket1", hostConfig{}) @@ -97,7 +99,7 @@ func (s *CmdTestSuite) TestGetNewClient(c *C) { c.Assert(err, IsNil) } -func (s *CmdTestSuite) TestNewConfigV2(c *C) { +func (s *TestSuite) TestNewConfigV2(c *C) { root, err := ioutil.TempDir(os.TempDir(), "mc-") c.Assert(err, IsNil) defer os.RemoveAll(root) @@ -153,7 +155,7 @@ func (s *CmdTestSuite) TestNewConfigV2(c *C) { } } -func (s *CmdTestSuite) TestRecursiveURL(c *C) { +func (s *TestSuite) TestRecursiveURL(c *C) { c.Assert(isURLRecursive("url..."), Equals, true) c.Assert(isURLRecursive("url.."), Equals, false) c.Assert(stripRecursiveURL("url..."), Equals, "url") @@ -162,7 +164,7 @@ func (s *CmdTestSuite) TestRecursiveURL(c *C) { c.Assert(stripRecursiveURL("...url"), Equals, "...url") } -func (s *CmdTestSuite) TestHostConfig(c *C) { +func (s *TestSuite) TestHostConfig(c *C) { hostcfg, err := getHostConfig("https://s3.amazonaws.com") c.Assert(err, IsNil) c.Assert(hostcfg.AccessKeyID, Equals, globalAccessKeyID) @@ -172,7 +174,7 @@ func (s *CmdTestSuite) TestHostConfig(c *C) { c.Assert(err, Not(IsNil)) } -func (s *CmdTestSuite) TestArgs2URL(c *C) { +func (s *TestSuite) TestArgs2URL(c *C) { URLs := []string{"localhost", "s3", "play", "playgo", "play.go", "https://s3-us-west-2.amazonaws.com"} expandedURLs, err := args2URLs(URLs) c.Assert(err, IsNil) @@ -184,7 +186,7 @@ func (s *CmdTestSuite) TestArgs2URL(c *C) { c.Assert(expandedURLs[5], Equals, "https://s3-us-west-2.amazonaws.com") } -func (s *CmdTestSuite) TestValidPERMS(c *C) { +func (s *TestSuite) TestValidPERMS(c *C) { perms := bucketPerms("private") c.Assert(perms.isValidBucketPERM(), Equals, true) c.Assert(perms.String(), Equals, "private") @@ -199,12 +201,12 @@ func (s *CmdTestSuite) TestValidPERMS(c *C) { c.Assert(perms.String(), Equals, "authenticated-read") } -func (s *CmdTestSuite) TestInvalidPERMS(c *C) { +func (s *TestSuite) TestInvalidPERMS(c *C) { perms := bucketPerms("invalid") c.Assert(perms.isValidBucketPERM(), Equals, false) } -func (s *CmdTestSuite) TestGetMcConfigDir(c *C) { +func (s *TestSuite) TestGetMcConfigDir(c *C) { dir, err := getMcConfigDir() c.Assert(err, IsNil) switch runtime.GOOS { @@ -222,7 +224,7 @@ func (s *CmdTestSuite) TestGetMcConfigDir(c *C) { c.Assert(mustGetMcConfigDir(), Equals, dir) } -func (s *CmdTestSuite) TestGetMcConfigPath(c *C) { +func (s *TestSuite) TestGetMcConfigPath(c *C) { dir, err := getMcConfigPath() c.Assert(err, IsNil) switch runtime.GOOS { @@ -240,7 +242,7 @@ func (s *CmdTestSuite) TestGetMcConfigPath(c *C) { c.Assert(mustGetMcConfigPath(), Equals, dir) } -func (s *CmdTestSuite) TestIsvalidAliasName(c *C) { +func (s *TestSuite) TestIsvalidAliasName(c *C) { c.Check(isValidAliasName("helloWorld0"), Equals, true) c.Check(isValidAliasName("h0SFD2k24Fdsa"), Equals, true) c.Check(isValidAliasName("fdslka-4"), Equals, true) @@ -251,7 +253,7 @@ func (s *CmdTestSuite) TestIsvalidAliasName(c *C) { c.Check(isValidAliasName("-fdslka"), Equals, false) } -func (s *CmdTestSuite) TestEmptyExpansions(c *C) { +func (s *TestSuite) TestEmptyExpansions(c *C) { url := getAliasURL("hello", nil) c.Assert(url, Equals, "hello") @@ -274,7 +276,7 @@ func (s *CmdTestSuite) TestEmptyExpansions(c *C) { c.Assert(url, Equals, "hello") } -func (s *CmdTestSuite) TestApp(c *C) { +func (s *TestSuite) TestApp(c *C) { err := app.Run([]string{""}) c.Assert(err, IsNil) } diff --git a/pb.go b/pb.go index befdf7ef..a87ad6e0 100644 --- a/pb.go +++ b/pb.go @@ -32,15 +32,15 @@ import ( "github.com/minio/mc/pkg/console" ) -type pbBarCmd int +type pbBar int const ( - pbBarCmdExtend pbBarCmd = iota - pbBarCmdProgress - pbBarCmdFinish - pbBarCmdPutError - pbBarCmdGetError - pbBarCmdSetCaption + pbBarExtend pbBar = iota + pbBarProgress + pbBarFinish + pbBarPutError + pbBarGetError + pbBarSetCaption ) type proxyReader struct { @@ -59,12 +59,12 @@ func (r *proxyReader) Close() (err error) { } type barMsg struct { - Cmd pbBarCmd + Op pbBar Arg interface{} } type barSend struct { - cmdCh chan<- barMsg + opCh chan<- barMsg finishCh <-chan bool } @@ -73,28 +73,28 @@ func (b *barSend) NewProxyReader(r io.ReadCloser) *proxyReader { } func (b barSend) Extend(total int64) { - b.cmdCh <- barMsg{Cmd: pbBarCmdExtend, Arg: total} + b.opCh <- barMsg{Op: pbBarExtend, Arg: total} } func (b barSend) Progress(progress int64) { - b.cmdCh <- barMsg{Cmd: pbBarCmdProgress, Arg: progress} + b.opCh <- barMsg{Op: pbBarProgress, Arg: progress} } func (b barSend) ErrorPut(size int64) { - b.cmdCh <- barMsg{Cmd: pbBarCmdPutError, Arg: size} + b.opCh <- barMsg{Op: pbBarPutError, Arg: size} } func (b barSend) ErrorGet(size int64) { - b.cmdCh <- barMsg{Cmd: pbBarCmdGetError, Arg: size} + b.opCh <- barMsg{Op: pbBarGetError, Arg: size} } func (b *barSend) SetCaption(c string) { - b.cmdCh <- barMsg{Cmd: pbBarCmdSetCaption, Arg: c} + b.opCh <- barMsg{Op: pbBarSetCaption, Arg: c} } func (b barSend) Finish() { - defer close(b.cmdCh) - b.cmdCh <- barMsg{Cmd: pbBarCmdFinish} + defer close(b.opCh) + b.opCh <- barMsg{Op: pbBarFinish} <-b.finishCh console.Println() } @@ -170,12 +170,12 @@ func newCpBar() barSend { bar.Format("[=> ]") } for msg := range cmdCh { - switch msg.Cmd { - case pbBarCmdSetCaption: + switch msg.Op { + case pbBarSetCaption: bar.Prefix(fixateBarCaption(msg.Arg.(string), getFixedWidth(bar.GetWidth(), 18))) - case pbBarCmdExtend: + case pbBarExtend: atomic.AddInt64(&bar.Total, msg.Arg.(int64)) - case pbBarCmdProgress: + case pbBarProgress: if bar.Total > 0 && !started { started = true bar.Start() @@ -184,15 +184,15 @@ func newCpBar() barSend { totalBytesRead += msg.Arg.(int64) bar.Add64(msg.Arg.(int64)) } - case pbBarCmdPutError: + case pbBarPutError: if totalBytesRead > msg.Arg.(int64) { bar.Set64(totalBytesRead - msg.Arg.(int64)) } - case pbBarCmdGetError: + case pbBarGetError: if msg.Arg.(int64) > 0 { bar.Add64(msg.Arg.(int64)) } - case pbBarCmdFinish: + case pbBarFinish: if started { bar.Finish() } diff --git a/session_test.go b/session_test.go index 2d3af137..aa532a1a 100644 --- a/session_test.go +++ b/session_test.go @@ -24,14 +24,14 @@ import ( . "gopkg.in/check.v1" ) -func (s *CmdTestSuite) TestValidSessionID(c *C) { +func (s *TestSuite) TestValidSessionID(c *C) { validSid := regexp.MustCompile("^[a-zA-Z]+$") sid := newSID(8) c.Assert(len(sid), Equals, 8) c.Assert(validSid.MatchString(sid), Equals, true) } -func (s *CmdTestSuite) TestSession(c *C) { +func (s *TestSuite) TestSession(c *C) { perr := createSessionDir() c.Assert(perr, IsNil) c.Assert(isSessionDirExists(), Equals, true) @@ -54,7 +54,7 @@ func (s *CmdTestSuite) TestSession(c *C) { c.Assert(perr, IsNil) } -func (s *CmdTestSuite) TestSessionContext(c *C) { +func (s *TestSuite) TestSessionContext(c *C) { err := app.Run([]string{os.Args[0], "session", "list"}) c.Assert(err, IsNil) c.Assert(console.IsExited, Equals, false)