From 3f52c951e7bd493dee70216c395774aa96c76c19 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 21 Nov 2015 17:55:38 -0800 Subject: [PATCH] testing: Remove all the console IsExited/IsError testing. --- cat_test.go | 17 -------- config_test.go | 80 ------------------------------------- cp_mirror_test.go | 70 +------------------------------- diff_test.go | 69 -------------------------------- ls_test.go | 62 ---------------------------- mb_access_test.go | 61 +--------------------------- mc_test.go | 13 ------ pipe_test.go | 23 ----------- pkg/console/console.go | 33 --------------- pkg/console/console_test.go | 9 ----- rm_test.go | 59 --------------------------- session_test.go | 57 -------------------------- share_test.go | 35 ---------------- 13 files changed, 2 insertions(+), 586 deletions(-) diff --git a/cat_test.go b/cat_test.go index e9ad776a..21e67dcf 100644 --- a/cat_test.go +++ b/cat_test.go @@ -22,7 +22,6 @@ import ( "os" "path/filepath" - "github.com/minio/mc/pkg/console" "github.com/minio/minio-xl/pkg/probe" . "gopkg.in/check.v1" ) @@ -54,19 +53,3 @@ func (s *TestSuite) TestCat(c *C) { objectPath = filepath.Join(root, "object2") c.Assert(catURL(objectPath), Not(IsNil)) } - -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) - - // reset back - console.IsExited = false - - err = app.Run([]string{os.Args[0], "cat", server.URL + "/invalid"}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, true) - - // reset back - console.IsExited = false -} diff --git a/config_test.go b/config_test.go index 61afab6a..bcecedc5 100644 --- a/config_test.go +++ b/config_test.go @@ -15,83 +15,3 @@ */ package main - -import ( - "os" - - "github.com/minio/mc/pkg/console" - . "gopkg.in/check.v1" -) - -func (s *TestSuite) TestConfigVersionContext(c *C) { - console.IsExited = false - err := app.Run([]string{os.Args[0], "config", "version"}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, false) - console.IsExited = false -} - -func (s *TestSuite) TestConfigAliasContext(c *C) { - console.IsExited = false - - err := app.Run([]string{os.Args[0], "config", "alias", "add", "test", "htt://test.io"}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, true) - - // reset back - console.IsExited = false - - err = app.Run([]string{os.Args[0], "config", "alias", "add", "new", "http://test.io"}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, false) - - // reset back - console.IsExited = false -} - -func (s *TestSuite) TestConfigHostContext(c *C) { - console.IsExited = false - - err := app.Run([]string{os.Args[0], - "config", - "host", - "add", - "*test.io", - "AKIKJAA5BMMU2RHO6IBB", - "V7f1CCwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr9", - }) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, true) - - // reset back - console.IsExited = false - - err = app.Run([]string{os.Args[0], - "config", - "host", - "add", - "http://my-example.com", - "AKIKJAA5BMMU2RHO6IBB", - "V7f1CCwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr9", - "S3v2", - }) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, false) - - // reset back - console.IsExited = false - - err = app.Run([]string{os.Args[0], "config", "host", "remove", "http://my-example.com"}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, false) - - // reset back - console.IsExited = false - - err = app.Run([]string{os.Args[0], "config", "host", "remove", "https://dl.minio.io:9000"}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, true) - - // reset back - console.IsExited = false -} diff --git a/cp_mirror_test.go b/cp_mirror_test.go index bb518319..10d5034d 100644 --- a/cp_mirror_test.go +++ b/cp_mirror_test.go @@ -16,17 +16,7 @@ package main -import ( - "bytes" - "io/ioutil" - "os" - "path/filepath" - "strconv" - - "github.com/minio/mc/pkg/console" - - . "gopkg.in/check.v1" -) +import . "gopkg.in/check.v1" func (s *TestSuite) TestCopyURLType(c *C) { // Valid Types. @@ -76,61 +66,3 @@ func (s *TestSuite) TestCopyURLType(c *C) { isRecursive = false c.Assert(guessCopyURLType(sourceURLs, targetURL, isRecursive), 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) - err := putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - } - - // reset back - console.IsExited = false - - err = app.Run([]string{os.Args[0], "mirror", source, target}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, false) - - // reset back - 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) - err := putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - } - - // reset back - console.IsExited = false - - target := filepath.Join(source, "random") - defer os.RemoveAll(target) - - err = app.Run([]string{os.Args[0], "cp", "--recursive", source, target}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, false) - - // reset back - console.IsError = false - console.IsExited = false -} diff --git a/diff_test.go b/diff_test.go index 55a9a7ff..c05aa9c2 100644 --- a/diff_test.go +++ b/diff_test.go @@ -15,72 +15,3 @@ */ package main - -import ( - "bytes" - "io/ioutil" - "os" - "path/filepath" - "strconv" - - "github.com/minio/mc/pkg/console" - "github.com/minio/minio-xl/pkg/probe" - . "gopkg.in/check.v1" -) - -func (s *TestSuite) TestDiffDirs(c *C) { - /// filesystem - root1, e := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(e, IsNil) - subDir1 := filepath.Join(root1, "subDir") - e = os.Mkdir(subDir1, 0755) - c.Assert(e, IsNil) - defer os.RemoveAll(root1) - - root2, e := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(e, IsNil) - subDir2 := filepath.Join(root2, "subDir") - e = os.Mkdir(subDir2, 0755) - defer os.RemoveAll(root2) - - var err *probe.Error - for i := 0; i < 10; i++ { - objectPath1 := filepath.Join(root1, "object"+strconv.Itoa(i)) - objectPath2 := filepath.Join(subDir1, "object"+strconv.Itoa(i)) - - data := "hello" - dataLen := len(data) - err = putTarget(objectPath1, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - err = putTarget(objectPath2, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - } - - for i := 0; i < 10; i++ { - objectPath1 := filepath.Join(root2, "object"+strconv.Itoa(i)) - objectPath2 := filepath.Join(subDir2, "object"+strconv.Itoa(i)) - data := "hello" - dataLen := len(data) - err = putTarget(objectPath1, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - err = putTarget(objectPath2, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - } - - e = app.Run([]string{os.Args[0], "diff", root1, root2}) - c.Assert(e, IsNil) - c.Assert(console.IsError, Equals, false) - c.Assert(console.IsExited, Equals, false) - - // reset back - console.IsExited = false -} - -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) - - // reset back - console.IsExited = false -} diff --git a/ls_test.go b/ls_test.go index 6a2659b4..c05aa9c2 100644 --- a/ls_test.go +++ b/ls_test.go @@ -15,65 +15,3 @@ */ package main - -import ( - "bytes" - "io/ioutil" - "os" - "path/filepath" - "strconv" - - "github.com/minio/mc/pkg/console" - . "gopkg.in/check.v1" -) - -func (s *TestSuite) TestLSContext(c *C) { - /// filesystem - root, e := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(e, IsNil) - defer os.RemoveAll(root) - - for i := 0; i < 10; i++ { - objectPath := filepath.Join(root, "object"+strconv.Itoa(i)) - data := "hello" - dataLen := len(data) - err := putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - } - - for i := 0; i < 10; i++ { - objectPath := server.URL + "/bucket/object" + strconv.Itoa(i) - data := "hello" - dataLen := len(data) - err := putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - } - - e = app.Run([]string{os.Args[0], "ls", root}) - c.Assert(e, IsNil) - c.Assert(console.IsError, Equals, false) - - // reset back - console.IsExited = false - - e = app.Run([]string{os.Args[0], "ls", "--recursive", root}) - c.Assert(e, IsNil) - c.Assert(console.IsError, Equals, false) - - // reset back - console.IsExited = false - - e = app.Run([]string{os.Args[0], "ls", server.URL + "/bucket"}) - c.Assert(e, IsNil) - c.Assert(console.IsError, Equals, false) - - // reset back - console.IsExited = false - - e = app.Run([]string{os.Args[0], "ls", "--recursive", server.URL + "/bucket"}) - c.Assert(e, IsNil) - c.Assert(console.IsError, Equals, false) - - // reset back - console.IsExited = false -} diff --git a/mb_access_test.go b/mb_access_test.go index d0ae289d..2cb017ae 100644 --- a/mb_access_test.go +++ b/mb_access_test.go @@ -16,15 +16,9 @@ package main -import ( - "os" - - "github.com/minio/mc/pkg/console" - . "gopkg.in/check.v1" -) +import . "gopkg.in/check.v1" func (s *TestSuite) TestMbAndAccess(c *C) { - // Instantiate client for URL. clnt, err := url2Client(server.URL + "/bucket") c.Assert(err, IsNil) @@ -43,56 +37,3 @@ func (s *TestSuite) TestMbAndAccess(c *C) { c.Assert(err, IsNil) c.Assert(perm.isPrivate(), Equals, true) } - -func (s *TestSuite) TestMBContext(c *C) { - err := app.Run([]string{os.Args[0], "mb", server.URL + "/bucket"}) - c.Assert(err, IsNil) - c.Assert(console.IsError, Equals, false) - - // reset back - console.IsError = false - - err = app.Run([]string{os.Args[0], "mb", server.URL + "/$.bucket"}) - c.Assert(err, IsNil) - c.Assert(console.IsError, Equals, true) - - // reset back - console.IsError = false -} - -func (s *TestSuite) TestAccessContext(c *C) { - err := app.Run([]string{os.Args[0], "access", "set", "private", server.URL + "/bucket"}) - c.Assert(err, IsNil) - c.Assert(console.IsError, Equals, false) - - // reset back - console.IsError = false - - err = app.Run([]string{os.Args[0], "access", "set", "public", server.URL + "/bucket"}) - c.Assert(err, IsNil) - c.Assert(console.IsError, Equals, false) - - // reset back - console.IsError = false - - err = app.Run([]string{os.Args[0], "access", "set", "readonly", server.URL + "/bucket"}) - c.Assert(err, IsNil) - c.Assert(console.IsError, Equals, false) - - // reset back - console.IsError = false - - err = app.Run([]string{os.Args[0], "access", "set", "authorized", server.URL + "/bucket"}) - c.Assert(err, IsNil) - c.Assert(console.IsError, Equals, false) - - // reset back - console.IsError = false - - err = app.Run([]string{os.Args[0], "access", "set", "invalid", server.URL + "/bucket"}) - c.Assert(err, IsNil) - - c.Assert(console.IsExited, Equals, true) - // reset back - console.IsExited = false -} diff --git a/mc_test.go b/mc_test.go index 52f035cf..89dc3889 100644 --- a/mc_test.go +++ b/mc_test.go @@ -28,7 +28,6 @@ import ( "net/http/httptest" "github.com/minio/cli" - "github.com/minio/mc/pkg/console" . "gopkg.in/check.v1" ) @@ -46,7 +45,6 @@ var app *cli.App 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 globalQuiet = true // quiet is set to turn of progress bar @@ -267,17 +265,6 @@ func (s *TestSuite) TestHumanizedTime(c *C) { c.Assert(hTime.Days, Not(Equals), int64(0)) } -func (s *TestSuite) TestVersionContext(c *C) { - console.IsExited = false - - err := app.Run([]string{os.Args[0], "version"}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, false) - - // reset back - console.IsExited = false -} - func (s *TestSuite) TestCommonPrefix(c *C) { c.Assert(commonPrefix("/usr", "/usr/local"), Equals, "/usr") c.Assert(commonPrefix("/uabbf", "/ursfad/ccc"), Equals, "/u") diff --git a/pipe_test.go b/pipe_test.go index 1914eba2..c05aa9c2 100644 --- a/pipe_test.go +++ b/pipe_test.go @@ -15,26 +15,3 @@ */ package main - -import ( - "io/ioutil" - "os" - - "github.com/minio/mc/pkg/console" - - . "gopkg.in/check.v1" -) - -func (s *TestSuite) TestPipeFail(c *C) { - /// filesystem - root, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(root) - - err = app.Run([]string{os.Args[0], "pipe", server.URL + "/bucket/"}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, true) - - // reset back - console.IsExited = false -} diff --git a/pkg/console/console.go b/pkg/console/console.go index f9e8f078..9d306230 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -31,12 +31,6 @@ import ( var ( // DebugPrint enables/disables console debug printing. DebugPrint = false - // IsTesting this flag indicates if IsExited should be set or not. - IsTesting = false - // IsExited sets this boolean value if Fatal is called when IsTesting is enabled. - IsExited = false - // IsError sets this boolean value if Error is called when IsTesting is enabled. - IsError = false // Used by the caller to print multiple lines atomically. Exposed by Lock/Unlock methods. publicMutex = &sync.Mutex{} @@ -69,66 +63,39 @@ var ( return } - // fatalQuitRoutine called after fatal message printing. - // by the user specific version. - fatalQuitRoutine = func() { - if !IsTesting { - os.Exit(1) - } - defer func() { - IsExited = true - }() - } - // Fatal print a error message and exit. Fatal = func(data ...interface{}) { consolePrint("Fatal", Theme["Fatal"], data...) - fatalQuitRoutine() return } // Fatalf print a error message with a format specified and exit. Fatalf = func(format string, data ...interface{}) { consolePrintf("Fatal", Theme["Fatal"], format, data...) - fatalQuitRoutine() return } // Fatalln print a error message with a new line and exit. Fatalln = func(data ...interface{}) { consolePrintln("Fatal", Theme["Fatal"], data...) - fatalQuitRoutine() return } - // errorQuitRoutine called after error message printing - // by the user specific version. - errorQuitRoutine = func() { - if IsTesting { - defer func() { - IsError = true - }() - } - } - // Error prints a error message. Error = func(data ...interface{}) { consolePrint("Error", Theme["Error"], data...) - errorQuitRoutine() return } // Errorf print a error message with a format specified. Errorf = func(format string, data ...interface{}) { consolePrintf("Error", Theme["Error"], format, data...) - errorQuitRoutine() return } // Errorln prints a error message with a new line. Errorln = func(data ...interface{}) { consolePrintln("Error", Theme["Error"], data...) - errorQuitRoutine() return } diff --git a/pkg/console/console_test.go b/pkg/console/console_test.go index d3fbad8b..c6048d17 100644 --- a/pkg/console/console_test.go +++ b/pkg/console/console_test.go @@ -40,12 +40,3 @@ func (s *MySuite) TestLock(c *C) { Print("") // Test for deadlocks. Unlock() } - -func (s *MySuite) TestTesting(c *C) { - // Enable testing - IsTesting = true - Fatalln("THIS IS A TEST MESSAGE. PLEASE INGORE.") - c.Assert(IsExited, Equals, true) - // reset back - IsExited = false -} diff --git a/rm_test.go b/rm_test.go index f1bcfc0f..c05aa9c2 100644 --- a/rm_test.go +++ b/rm_test.go @@ -15,62 +15,3 @@ */ package main - -import ( - "bytes" - "io/ioutil" - "os" - "path/filepath" - "strconv" - - "github.com/minio/mc/pkg/console" - "github.com/minio/minio-xl/pkg/probe" - . "gopkg.in/check.v1" -) - -func (s *TestSuite) TestRemove(c *C) { - /// filesystem - root, e := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(e, IsNil) - defer os.RemoveAll(root) - - objectPath := filepath.Join(root, "object1") - data := "hello" - dataLen := len(data) - - var err *probe.Error - err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - - e = app.Run([]string{os.Args[0], "rm", objectPath}) - c.Assert(e, IsNil) - c.Assert(console.IsError, Equals, false) - - // reset back - console.IsExited = false - - for i := 0; i < 10; i++ { - objectPath := filepath.Join(root, "object"+strconv.Itoa(i)) - data := "hello" - dataLen := len(data) - err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - } - - // reset back - console.IsExited = false - - e = app.Run([]string{os.Args[0], "rm", "--recursive", root}) - c.Assert(e, IsNil) - c.Assert(console.IsExited, Equals, true) - - // reset back - console.IsExited = false - - app.Run([]string{os.Args[0], "rm", "--recursive", "--force", root}) - c.Assert(e, IsNil) - c.Assert(console.IsExited, Equals, false) - - // reset back - console.IsExited = false -} diff --git a/session_test.go b/session_test.go index 2b4159a7..6528b203 100644 --- a/session_test.go +++ b/session_test.go @@ -17,10 +17,8 @@ package main import ( - "os" "regexp" - "github.com/minio/mc/pkg/console" . "gopkg.in/check.v1" ) @@ -53,58 +51,3 @@ func (s *TestSuite) TestSession(c *C) { err = savedSession.Delete() c.Assert(err, IsNil) } - -func (s *TestSuite) TestSessionContext(c *C) { - e := app.Run([]string{os.Args[0], "session", "list"}) - c.Assert(e, IsNil) - c.Assert(console.IsExited, Equals, false) - - // reset back - console.IsExited = false - - e = app.Run([]string{os.Args[0], "session", "clear", "all"}) - c.Assert(e, IsNil) - c.Assert(console.IsExited, Equals, false) - - // reset back - console.IsExited = false - - /* - e = app.Run([]string{os.Args[0], "session", "resume", "invalid"}) - c.Assert(e, IsNil) - c.Assert(console.IsExited, Equals, true) - */ - - // reset back - console.IsExited = false - - e = app.Run([]string{os.Args[0], "session", "clear", "invalid"}) - c.Assert(e, IsNil) - c.Assert(console.IsExited, Equals, true) - - // reset back - console.IsExited = false - - err := createSessionDir() - c.Assert(err, IsNil) - c.Assert(isSessionDirExists(), Equals, true) - - // reset back - console.IsExited = false - - session := newSessionV5() - c.Assert(session.Header.CommandArgs, IsNil) - c.Assert(len(session.SessionID), Equals, 8) - - err = session.Save() - c.Assert(err, IsNil) - - c.Assert(session.Close(), IsNil) - - e = app.Run([]string{os.Args[0], "session", "clear", session.SessionID}) - c.Assert(e, IsNil) - c.Assert(console.IsExited, Equals, false) - - // reset back - console.IsExited = false -} diff --git a/share_test.go b/share_test.go index 9e397190..c05aa9c2 100644 --- a/share_test.go +++ b/share_test.go @@ -15,38 +15,3 @@ */ package main - -import ( - "os" - - "github.com/minio/mc/pkg/console" - . "gopkg.in/check.v1" -) - -func (s *TestSuite) TestShareFailure(c *C) { - objectURL := server.URL + "/bucket/object1" - - // Invalid duration format ``1hr``. - err := app.Run([]string{os.Args[0], "share", "download", "--expire=1hr", objectURL}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, true) - - // Reset back. - console.IsExited = false - - // Too high duration 169h, maximum is 168h i.e 7days. - err = app.Run([]string{os.Args[0], "share", "download", "--expire=169hr", objectURL}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, true) - - // Reset back - console.IsExited = false - - // Too low duration 0s, minimum required is 1s. - err = app.Run([]string{os.Args[0], "share", "download", "--expire=0s", objectURL}) - c.Assert(err, IsNil) - c.Assert(console.IsExited, Equals, true) - - // Reset back. - console.IsExited = false -}