func TestDownloadError(t *testing.T) { s, names, _ := dlLoggingSvc([]byte{1, 2, 3}) opts := &s3manager.DownloadOptions{S3: s, PartSize: 1, Concurrency: 1} num := 0 s.Handlers.Send.PushBack(func(r *aws.Request) { num++ if num > 1 { r.HTTPResponse.StatusCode = 400 r.HTTPResponse.Body = ioutil.NopCloser(bytes.NewReader([]byte{})) } }) d := s3manager.NewDownloader(opts) w := newDLWriter(3) n, err := d.Download(w, &s3.GetObjectInput{ Bucket: aws.String("bucket"), Key: aws.String("key"), }) assert.NotNil(t, err) assert.Equal(t, int64(1), n) assert.Equal(t, []string{"GetObject", "GetObject"}, *names) assert.Equal(t, []byte{1, 0, 0}, w.buf) }
func validate(t *testing.T, key string, md5value string) { mgr := s3manager.NewDownloader(nil) params := &s3.GetObjectInput{Bucket: bucketName, Key: &key} w := newDLWriter(1024 * 1024 * 20) n, err := mgr.Download(w, params) assert.NoError(t, err) assert.Equal(t, md5value, fmt.Sprintf("%x", md5.Sum(w.buf[0:n]))) }
func TestDownloadZero(t *testing.T) { s, names, ranges := dlLoggingSvc([]byte{}) opts := &s3manager.DownloadOptions{S3: s} d := s3manager.NewDownloader(opts) w := newDLWriter(0) n, err := d.Download(w, &s3.GetObjectInput{ Bucket: aws.String("bucket"), Key: aws.String("key"), }) assert.Nil(t, err) assert.Equal(t, int64(0), n) assert.Equal(t, []string{"GetObject"}, *names) assert.Equal(t, []string{"bytes=0-5242879"}, *ranges) }
func TestDownloadSetPartSize(t *testing.T) { s, names, ranges := dlLoggingSvc([]byte{1, 2, 3}) opts := &s3manager.DownloadOptions{S3: s, PartSize: 1, Concurrency: 1} d := s3manager.NewDownloader(opts) w := newDLWriter(3) n, err := d.Download(w, &s3.GetObjectInput{ Bucket: aws.String("bucket"), Key: aws.String("key"), }) assert.Nil(t, err) assert.Equal(t, int64(3), n) assert.Equal(t, []string{"GetObject", "GetObject", "GetObject"}, *names) assert.Equal(t, []string{"bytes=0-0", "bytes=1-1", "bytes=2-2"}, *ranges) assert.Equal(t, []byte{1, 2, 3}, w.buf) }
func TestDownloadOrder(t *testing.T) { s, names, ranges := dlLoggingSvc(buf12MB) opts := &s3manager.DownloadOptions{S3: s, Concurrency: 1} d := s3manager.NewDownloader(opts) w := newDLWriter(len(buf12MB)) n, err := d.Download(w, &s3.GetObjectInput{ Bucket: aws.String("bucket"), Key: aws.String("key"), }) assert.Nil(t, err) assert.Equal(t, int64(len(buf12MB)), n) assert.Equal(t, []string{"GetObject", "GetObject", "GetObject"}, *names) assert.Equal(t, []string{"bytes=0-5242879", "bytes=5242880-10485759", "bytes=10485760-15728639"}, *ranges) count := 0 for _, b := range w.buf { count += int(b) } assert.Equal(t, 0, count) }