diff --git a/cat_test.go b/cat_test.go index 1315d40e..9f957aee 100644 --- a/cat_test.go +++ b/cat_test.go @@ -21,24 +21,11 @@ import ( "io/ioutil" "os" "path/filepath" - "runtime" . "github.com/minio/check" ) func (s *CmdTestSuite) TestCatCmd(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - /// filesystem root, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) diff --git a/cmd_test.go b/cmd_test.go index a2238f39..14e31abd 100644 --- a/cmd_test.go +++ b/cmd_test.go @@ -21,7 +21,6 @@ import ( "io" "io/ioutil" "os" - "os/user" "path" "path/filepath" "runtime" @@ -46,6 +45,19 @@ func mustGetMcConfigDir() string { return dir } +func (s *CmdTestSuite) SetUpSuite(c *C) { + configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") + c.Assert(err, IsNil) + customConfigDir = configDir + + _, err = doConfig("generate", nil) + c.Assert(err, IsNil) +} + +func (s *CmdTestSuite) TearDownSuite(c *C) { + os.RemoveAll(customConfigDir) +} + func (s *CmdTestSuite) TestGetNewClient(c *C) { _, err := getNewClient("http://example.com/bucket1", &hostConfig{}, false) c.Assert(err, IsNil) @@ -131,25 +143,17 @@ func (s *CmdTestSuite) TestInvalidACL(c *C) { } func (s *CmdTestSuite) TestGetMcConfigDir(c *C) { - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = "mc/" - default: - mcConfigDir = ".mc/" - } - u, err := user.Current() - c.Assert(err, IsNil) dir, err := getMcConfigDir() c.Assert(err, IsNil) switch runtime.GOOS { case "linux": - c.Assert(dir, Equals, path.Join(u.HomeDir, ".mc/")) + c.Assert(dir, Equals, path.Join(customConfigDir, ".mc/")) case "windows": - c.Assert(dir, Equals, path.Join(u.HomeDir, "mc/")) + c.Assert(dir, Equals, path.Join(customConfigDir, "mc/")) case "darwin": - c.Assert(dir, Equals, path.Join(u.HomeDir, ".mc/")) + c.Assert(dir, Equals, path.Join(customConfigDir, ".mc/")) case "freebsd": - c.Assert(dir, Equals, path.Join(u.HomeDir, ".mc/")) + c.Assert(dir, Equals, path.Join(customConfigDir, ".mc/")) default: c.Fail() } @@ -258,34 +262,7 @@ func (s *CmdTestSuite) TestIsValidRetry(c *C) { c.Assert(isValidRetry(iodine.New(opError, nil)), Equals, false) } -func (s *CmdTestSuite) TestConfig(c *C) { - root, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(root) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = root - default: - mcConfigDir = root - } - - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) -} - func (s *CmdTestSuite) TestCommonMethods(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - /// filesystem root, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) diff --git a/config.go b/config.go index 17b38543..c7646966 100644 --- a/config.go +++ b/config.go @@ -38,8 +38,20 @@ var cache struct { configLoaded bool // set to true if cache is valid. } +// customConfigDir used internally only by test functions +var customConfigDir string + // getMcConfigDir - construct minio client config folder func getMcConfigDir() (string, error) { + if customConfigDir != "" { + // For windows the path is slightly different + switch runtime.GOOS { + case "windows": + return path.Join(customConfigDir, mcConfigWindowsDir), nil + default: + return path.Join(customConfigDir, mcConfigDir), nil + } + } u, err := user.Current() if err != nil { return "", iodine.New(err, nil) diff --git a/cp_test.go b/cp_test.go index 8533646c..bce5af41 100644 --- a/cp_test.go +++ b/cp_test.go @@ -21,27 +21,15 @@ import ( "io/ioutil" "os" "path/filepath" - "runtime" "strconv" . "github.com/minio/check" ) -var bar = newCpBar() +var bar barSend func (s *CmdTestSuite) TestCpTypeA(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - + globalQuietFlag = true /// filesystem source, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) @@ -64,18 +52,6 @@ func (s *CmdTestSuite) TestCpTypeA(c *C) { } func (s *CmdTestSuite) TestCpTypeB(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - /// filesystem source, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) @@ -97,18 +73,6 @@ func (s *CmdTestSuite) TestCpTypeB(c *C) { } func (s *CmdTestSuite) TestCpTypeC(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - /// filesystem source, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) diff --git a/diff_test.go b/diff_test.go index 86fb7685..1ef328ea 100644 --- a/diff_test.go +++ b/diff_test.go @@ -21,25 +21,12 @@ import ( "io/ioutil" "os" "path/filepath" - "runtime" "strconv" . "github.com/minio/check" ) func (s *CmdTestSuite) TestDiffObjects(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - /// filesystem root1, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) @@ -67,18 +54,6 @@ func (s *CmdTestSuite) TestDiffObjects(c *C) { } func (s *CmdTestSuite) TestDiffDirs(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - /// filesystem root1, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) diff --git a/globals.go b/globals.go index 19347a41..c32a2285 100644 --- a/globals.go +++ b/globals.go @@ -26,7 +26,7 @@ var ( ) // mc configuration related constants -var ( +const ( mcConfigDir = ".mc/" mcConfigWindowsDir = "mc/" mcConfigFile = "config.json" diff --git a/ls_test.go b/ls_test.go index e75e8172..95976047 100644 --- a/ls_test.go +++ b/ls_test.go @@ -21,25 +21,12 @@ import ( "io/ioutil" "os" "path/filepath" - "runtime" "strconv" . "github.com/minio/check" ) func (s *CmdTestSuite) TestLSNonRecursive(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - /// filesystem root, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) @@ -60,18 +47,6 @@ func (s *CmdTestSuite) TestLSNonRecursive(c *C) { } func (s *CmdTestSuite) TestLSRecursive(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - /// filesystem root, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) diff --git a/mb_access_test.go b/mb_access_test.go index 40c364cc..30b2450b 100644 --- a/mb_access_test.go +++ b/mb_access_test.go @@ -20,24 +20,11 @@ import ( "io/ioutil" "os" "path/filepath" - "runtime" . "github.com/minio/check" ) func (s *CmdTestSuite) TestMbCmd(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - /// filesystem root, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil) @@ -48,18 +35,6 @@ func (s *CmdTestSuite) TestMbCmd(c *C) { } func (s *CmdTestSuite) TestAccessCmd(c *C) { - configDir, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(configDir) - switch runtime.GOOS { - case "windows": - mcConfigWindowsDir = configDir - default: - mcConfigDir = configDir - } - _, err = doConfig("generate", nil) - c.Assert(err, IsNil) - /// filesystem root, err := ioutil.TempDir(os.TempDir(), "cmd-") c.Assert(err, IsNil)