mirror of
https://github.com/minio/mc.git
synced 2025-11-13 12:22:45 +03:00
67 lines
1.8 KiB
Go
67 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"
|
|
"io"
|
|
"sync"
|
|
|
|
. "github.com/minio-io/check"
|
|
)
|
|
|
|
type CmdTestSuite struct{}
|
|
|
|
var _ = Suite(&CmdTestSuite{})
|
|
|
|
func (s *CmdTestSuite) TestCopyToSingleTarget(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 := []string{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)
|
|
}
|