From 3414a0fd3b1f01d5cdead650d821509317135621 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 14 Jul 2015 16:42:54 -0700 Subject: [PATCH] Remove cp and sync tests for now, bring them back with console.Test, additionally close DataFP inside session.Close() --- cp_test.go | 190 ------------------------------------------------ main.go | 7 ++ session-v2.go | 14 ++-- session_test.go | 1 - sync_test.go | 153 -------------------------------------- 5 files changed, 13 insertions(+), 352 deletions(-) delete mode 100644 cp_test.go delete mode 100644 sync_test.go diff --git a/cp_test.go b/cp_test.go deleted file mode 100644 index 9dd6fa65..00000000 --- a/cp_test.go +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Minio Client (C) 2015 Minio, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -/* -import ( - "bytes" - "io/ioutil" - "os" - "path/filepath" - "strconv" - - . "github.com/minio/check" -) - -var barCp barSend - -func (s *CmdTestSuite) TestCpTypeA(c *C) { - /// filesystem - source, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(source) - - cps, err := newSession() - c.Assert(err, IsNil) - - sourcePath := filepath.Join(source, "object1") - data := "hello" - dataLen := len(data) - err = putTarget(sourcePath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - - target, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(target) - targetPath := filepath.Join(target, "newObject1") - - cps.URLs = append(cps.URLs, sourcePath) - cps.URLs = append(cps.URLs, targetPath) - for err := range doCopyCmdSession(barCp, cps) { - c.Assert(err, IsNil) - } - - cps, err = newSession() - c.Assert(err, IsNil) - targetURL := server.URL + "/bucket/newObject" - - cps.URLs = append(cps.URLs, sourcePath) - cps.URLs = append(cps.URLs, targetURL) - for err := range doCopyCmdSession(barCp, cps) { - c.Assert(err, IsNil) - } -} - -func (s *CmdTestSuite) TestCpTypeB(c *C) { - /// filesystem - source, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(source) - - sourcePath := filepath.Join(source, "object1") - data := "hello" - dataLen := len(data) - err = putTarget(sourcePath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - - target, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(target) - - cps, err := newSession() - c.Assert(err, IsNil) - - cps.URLs = append(cps.URLs, sourcePath) - cps.URLs = append(cps.URLs, target) - for err := range doCopyCmdSession(barCp, cps) { - c.Assert(err, IsNil) - } - - cps, err = newSession() - c.Assert(err, IsNil) - - targetURL := server.URL + "/bucket" - cps.URLs = append(cps.URLs, sourcePath) - cps.URLs = append(cps.URLs, targetURL) - for err := range doCopyCmdSession(barCp, cps) { - c.Assert(err, IsNil) - } -} - -func (s *CmdTestSuite) TestCpTypeC(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) - } - - target, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(target) - - cps, err := newSession() - c.Assert(err, IsNil) - - cps.URLs = append(cps.URLs, source+"...") - cps.URLs = append(cps.URLs, target) - for err := range doCopyCmdSession(barCp, cps) { - c.Assert(err, IsNil) - } - - cps, err = newSession() - c.Assert(err, IsNil) - - cps.URLs = append(cps.URLs, source+"...") - cps.URLs = append(cps.URLs, server.URL+"/bucket") - for err := range doCopyCmdSession(barCp, cps) { - c.Assert(err, IsNil) - } -} - -func (s *CmdTestSuite) TestCpTypeD(c *C) { - /// filesystem - source1, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - source2, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(source1) - defer os.RemoveAll(source2) - - for i := 0; i < 10; i++ { - objectPath := filepath.Join(source1, "object"+strconv.Itoa(i)) - data := "hello" - dataLen := len(data) - err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - } - - for i := 10; i < 20; i++ { - objectPath := filepath.Join(source2, "object"+strconv.Itoa(i)) - data := "hello" - dataLen := len(data) - err = putTarget(objectPath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - } - - target, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(target) - - cps, err := newSession() - c.Assert(err, IsNil) - cps.URLs = append(cps.URLs, source1+"...") - cps.URLs = append(cps.URLs, source2+"...") - cps.URLs = append(cps.URLs, target) - for err := range doCopyCmdSession(barCp, cps) { - c.Assert(err, IsNil) - } - - cps, err = newSession() - c.Assert(err, IsNil) - targetURL := server.URL + "/bucket" - cps.URLs = append(cps.URLs, source1+"...") - cps.URLs = append(cps.URLs, source2+"...") - cps.URLs = append(cps.URLs, targetURL) - for err := range doCopyCmdSession(barCp, cps) { - c.Assert(err, IsNil) - } -} -*/ diff --git a/main.go b/main.go index 175004be..739a79e6 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,12 @@ func checkConfig() { console.Fatalf("Unable to determine current user. %s\n", err) } + if !isSessionDirExists() { + if err := createSessionDir(); err != nil { + console.Fatalf("Unable to create session directory. %s\n", err) + } + } + // If config doesn't exist, do not attempt to read it if !isMcConfigExists() { return @@ -45,6 +51,7 @@ func checkConfig() { if err != nil { console.Fatalf("Unable to read config file. %s\n", err) } + } // Get os/arch/platform specific information. diff --git a/session-v2.go b/session-v2.go index 8ebc8141..b777aa10 100644 --- a/session-v2.go +++ b/session-v2.go @@ -63,17 +63,10 @@ type sessionV2 struct { // provides a new session func newSessionV2() *sessionV2 { - // TODO: Blindly create .mc and session dirs at init and remove these checks -ab. if !isMcConfigExists() { console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{}) } - if !isSessionDirExists() { - if err := createSessionDir(); err != nil { - console.Fatalf("Unable to create session directory. %s\n", err) - } - } - s := &sessionV2{} s.Header = &sessionV2Header{} s.Header.Version = "1.1.0" @@ -146,7 +139,12 @@ func (s *sessionV2) Close() error { s.mutex.Lock() defer s.mutex.Unlock() - err := os.Remove(getSessionDataFile(s.SessionID)) + err := s.DataFP.Close() + if err != nil { + return iodine.New(err, nil) + } + + err = os.Remove(getSessionDataFile(s.SessionID)) if err != nil { return iodine.New(err, nil) } diff --git a/session_test.go b/session_test.go index 0ae8d958..c34cf6f5 100644 --- a/session_test.go +++ b/session_test.go @@ -35,7 +35,6 @@ func (s *CmdTestSuite) TestSession(c *C) { c.Assert(isSessionDirExists(), Equals, true) session := newSessionV2() - c.Assert(err, IsNil) c.Assert(session.Header.CommandArgs, IsNil) c.Assert(len(session.SessionID), Equals, 8) diff --git a/sync_test.go b/sync_test.go deleted file mode 100644 index a7d62c0d..00000000 --- a/sync_test.go +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Minio Client (C) 2015 Minio, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -/* -import ( - "bytes" - "io/ioutil" - "os" - "path/filepath" - "strconv" - - . "github.com/minio/check" -) - -var barSync barSend - -func (s *CmdTestSuite) TestSyncTypeA(c *C) { - /// filesystem - source, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(source) - - sourcePath := filepath.Join(source, "object1") - data := "hello" - dataLen := len(data) - err = putTarget(sourcePath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - - target, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(target) - targetPath := filepath.Join(target, "newObject1") - - ss, err := newSession() - c.Assert(err, IsNil) - ss.URLs = append(ss.URLs, sourcePath) - ss.URLs = append(ss.URLs, targetPath) - for err := range doSyncCmdSession(barSync, ss) { - c.Assert(err, IsNil) - } - - ss, err = newSession() - c.Assert(err, IsNil) - targetURL := server.URL + "/bucket/newObject" - ss.URLs = append(ss.URLs, sourcePath) - ss.URLs = append(ss.URLs, targetURL) - for err := range doSyncCmdSession(barSync, ss) { - c.Assert(err, IsNil) - } -} - -func (s *CmdTestSuite) TestSyncTypeB(c *C) { - /// filesystem - source, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(source) - - sourcePath := filepath.Join(source, "object1") - data := "hello" - dataLen := len(data) - err = putTarget(sourcePath, int64(dataLen), bytes.NewReader([]byte(data))) - c.Assert(err, IsNil) - - target, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(target) - - ss, err := newSession() - c.Assert(err, IsNil) - ss.URLs = append(ss.URLs, sourcePath) - ss.URLs = append(ss.URLs, target) - for err := range doSyncCmdSession(barSync, ss) { - c.Assert(err, IsNil) - } - - ss, err = newSession() - c.Assert(err, IsNil) - targetURL := server.URL + "/bucket" - ss.URLs = append(ss.URLs, sourcePath) - ss.URLs = append(ss.URLs, targetURL) - for err := range doSyncCmdSession(barSync, ss) { - c.Assert(err, IsNil) - } -} - -func (s *CmdTestSuite) TestSyncTypeC(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) - } - - target, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(target) - - ss, err := newSession() - c.Assert(err, IsNil) - ss.URLs = append(ss.URLs, source+"...") - ss.URLs = append(ss.URLs, target) - for err := range doSyncCmdSession(barSync, ss) { - c.Assert(err, IsNil) - } - - targetURL := server.URL + "/bucket" - ss, err = newSession() - c.Assert(err, IsNil) - ss.URLs = append(ss.URLs, source+"...") - ss.URLs = append(ss.URLs, targetURL) - for err := range doSyncCmdSession(barSync, ss) { - c.Assert(err, IsNil) - } - - target1, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(target1) - - target2, err := ioutil.TempDir(os.TempDir(), "cmd-") - c.Assert(err, IsNil) - defer os.RemoveAll(target2) - - ss, err = newSession() - c.Assert(err, IsNil) - ss.URLs = append(ss.URLs, source+"...") - ss.URLs = append(ss.URLs, target1) - ss.URLs = append(ss.URLs, target2) - for err := range doSyncCmdSession(barSync, ss) { - c.Assert(err, IsNil) - } -} -*/