1
0
mirror of https://github.com/minio/mc.git synced 2025-11-13 12:22:45 +03:00
Files
mc/cmd_test.go
Frederick F. Kautz IV 8b5eff1040 Adding test for copy
2015-04-16 20:27:19 -07:00

66 lines
1.8 KiB
Go

/*
* Mini Copy, (C) 2014, 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"
"crypto/md5"
"encoding/hex"
. "github.com/minio-io/check"
"io"
"sync"
)
type CmdTestSuite struct{}
var _ = Suite(&CmdTestSuite{})
func (s *CmdTestSuite) TestFileToS3Copy(c *C) {
manager := &mockClientManager{}
sourceURL, err := parseURL("foo", nil)
c.Assert(err, IsNil)
data := "Hello World"
md5Sum := md5.Sum([]byte(data))
hexMd5 := hex.EncodeToString(md5Sum[:])
dataLength := int64(len(data))
targetURL, err := parseURL("bar", nil)
c.Assert(err, IsNil)
targetURLs := []*parsedURL{targetURL}
sourceReader, sourceWriter := io.Pipe()
targetReader, targetWriter := io.Pipe()
var resultBuffer bytes.Buffer
wg := &sync.WaitGroup{}
wg.Add(2)
go func() {
io.Copy(sourceWriter, bytes.NewBufferString("Hello World"))
sourceWriter.Close()
wg.Done()
}()
go func() {
io.Copy(&resultBuffer, targetReader)
wg.Done()
}()
manager.On("getSourceReader", sourceURL).Return(sourceReader, dataLength, hexMd5, nil).Once()
manager.On("getTargetWriter", targetURL, hexMd5, dataLength).Return(targetWriter, nil).Once()
doCopyCmd(manager, sourceURL, targetURLs)
wg.Wait()
c.Assert(err, IsNil)
c.Assert(resultBuffer.String(), DeepEquals, data)
}