1
0
mirror of https://github.com/minio/mc.git synced 2025-11-13 12:22:45 +03:00

Recreating mock for new test

This commit is contained in:
Frederick F. Kautz IV
2015-04-17 18:24:46 -07:00
parent d2e68e4ab3
commit 2b4da8aa12
3 changed files with 62 additions and 40 deletions

View File

@@ -22,6 +22,7 @@ import (
"io" "io"
"sync" "sync"
"errors"
. "github.com/minio-io/check" . "github.com/minio-io/check"
) )
@@ -30,7 +31,7 @@ type CmdTestSuite struct{}
var _ = Suite(&CmdTestSuite{}) var _ = Suite(&CmdTestSuite{})
func (s *CmdTestSuite) TestCopyToSingleTarget(c *C) { func (s *CmdTestSuite) TestCopyToSingleTarget(c *C) {
manager := &mockClientManager{} manager := &MockclientManager{}
sourceURL, err := parseURL("foo", nil) sourceURL, err := parseURL("foo", nil)
c.Assert(err, IsNil) c.Assert(err, IsNil)
@@ -64,3 +65,18 @@ func (s *CmdTestSuite) TestCopyToSingleTarget(c *C) {
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(resultBuffer.String(), DeepEquals, data) c.Assert(resultBuffer.String(), DeepEquals, data)
} }
func (s *CmdTestSuite) TestCopyRecursive(c *C) {
c.Skip("Incomplete")
sourceURL, err := parseURL("foo", nil)
c.Assert(err, IsNil)
targetURL, err := parseURL("bar", nil)
c.Assert(err, IsNil)
targetURLs := []string{targetURL}
manager := &MockclientManager{}
manager.On("getNewClient", sourceURL, false).Return(nil, errors.New("foo")).Once()
doCopyCmdRecursive(manager, sourceURL, targetURLs)
}

View File

@@ -0,0 +1,45 @@
package main
import "github.com/stretchr/testify/mock"
import "github.com/minio-io/mc/pkg/client"
import "io"
// MockclientManager is a mock for testing, please ignore.
type MockclientManager struct {
mock.Mock
}
func (m *MockclientManager) getSourceReader(urlStr string) (io.ReadCloser, int64, string, error) {
ret := m.Called(urlStr)
r0 := ret.Get(0).(io.ReadCloser)
r1 := ret.Get(1).(int64)
r2 := ret.Get(2).(string)
r3 := ret.Error(3)
return r0, r1, r2, r3
}
func (m *MockclientManager) getTargetWriter(urlStr string, md5Hex string, length int64) (io.WriteCloser, error) {
ret := m.Called(urlStr, md5Hex, length)
r0 := ret.Get(0).(io.WriteCloser)
r1 := ret.Error(1)
return r0, r1
}
func (m *MockclientManager) getNewClient(urlStr string, debug bool) (client.Client, error) {
ret := m.Called(urlStr, debug)
var r0 client.Client
untypedR0 := ret.Get(0)
if untypedR0 != nil {
r0 = untypedR0.(client.Client)
} else {
r0 = nil
}
r1 := ret.Error(1)
return r0, r1
}

View File

@@ -1,39 +0,0 @@
package main
import "github.com/stretchr/testify/mock"
import (
"github.com/minio-io/mc/pkg/client"
"io"
)
type mockClientManager struct {
mock.Mock
}
func (m *mockClientManager) getSourceReader(sourceURL string) (io.ReadCloser, int64, string, error) {
ret := m.Called(sourceURL)
r0 := ret.Get(0).(io.ReadCloser)
r1 := ret.Get(1).(int64)
r2 := ret.Get(2).(string)
r3 := ret.Error(3)
return r0, r1, r2, r3
}
func (m *mockClientManager) getTargetWriter(targetURL string, md5Hex string, length int64) (io.WriteCloser, error) {
ret := m.Called(targetURL, md5Hex, length)
r0 := ret.Get(0).(io.WriteCloser)
r1 := ret.Error(1)
return r0, r1
}
func (m *mockClientManager) getNewClient(targetURL string, debug bool) (client.Client, error) {
ret := m.Called(targetURL, debug)
r0 := ret.Get(0).(client.Client)
r1 := ret.Error(1)
return r0, r1
}