2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-23 13:17:42 +00:00

Use local instance of minio server.

Need to figure out how to have tests automatically start and kill
server.
This commit is contained in:
Chris Howey 2015-11-07 06:43:15 -06:00 committed by Alexander Neumann
parent e2445f4c97
commit 69a9adc4c3
3 changed files with 28 additions and 28 deletions

3
Godeps/Godeps.json generated
View File

@ -24,8 +24,7 @@
}, },
{ {
"ImportPath": "github.com/minio/minio-go", "ImportPath": "github.com/minio/minio-go",
"Comment": "v0.2.5-58-g5c3a491", "Rev": "61f6570da0edd761974216c9ed5da485d3cc0c99"
"Rev": "5c3a4919116141f088990bd6ee385877648c7a25"
}, },
{ {
"ImportPath": "github.com/pkg/sftp", "ImportPath": "github.com/pkg/sftp",

View File

@ -3,9 +3,7 @@ package s3
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"io" "io"
"io/ioutil"
"os" "os"
"strings" "strings"
@ -48,8 +46,12 @@ func Open(regionname, bucketname string) (backend.Backend, error) {
} }
} else { } else {
// S3 compatible endpoint // S3 compatible endpoint
if strings.Contains(regionname, "localhost") || strings.Contains(regionname, "127.0.0.1") {
config.Endpoint = "http://" + regionname
} else {
config.Endpoint = "https://" + regionname config.Endpoint = "https://" + regionname
} }
}
s3api, s3err := minio.New(config) s3api, s3err := minio.New(config)
if s3err != nil { if s3err != nil {
@ -142,27 +144,9 @@ func (be *S3Backend) Get(t backend.Type, name string) (io.ReadCloser, error) {
// GetReader returns an io.ReadCloser for the Blob with the given name of // GetReader returns an io.ReadCloser for the Blob with the given name of
// type t at offset and length. If length is 0, the reader reads until EOF. // type t at offset and length. If length is 0, the reader reads until EOF.
func (be *S3Backend) GetReader(t backend.Type, name string, offset, length uint) (io.ReadCloser, error) { func (be *S3Backend) GetReader(t backend.Type, name string, offset, length uint) (io.ReadCloser, error) {
rc, err := be.Get(t, name) path := s3path(t, name)
if err != nil { rc, _, err := be.s3api.GetPartialObject(be.bucketname, path, int64(offset), int64(length))
return nil, err return rc, err
}
n, errc := io.CopyN(ioutil.Discard, rc, int64(offset))
if errc != nil {
return nil, errc
} else if n != int64(offset) {
return nil, fmt.Errorf("less bytes read than expected, read: %d, expected: %d", n, offset)
}
if length == 0 {
return rc, nil
}
return backend.LimitReadCloser(rc, int64(length)), nil
} }
// Test returns true if a blob of the given type and name exists in the backend. // Test returns true if a blob of the given type and name exists in the backend.

View File

@ -1,17 +1,34 @@
package backend_test package backend_test
import ( import (
"os"
"testing" "testing"
"github.com/minio/minio-go"
bes3 "github.com/restic/restic/backend/s3" bes3 "github.com/restic/restic/backend/s3"
. "github.com/restic/restic/test"
) )
func TestS3Backend(t *testing.T) { func TestS3Backend(t *testing.T) {
s, err := bes3.Open("play.minio.io:9000", "restictestbucket") config := minio.Config{
AccessKeyID: os.Getenv("AWS_ACCESS_KEY_ID"),
SecretAccessKey: os.Getenv("AWS_SECRET_ACCESS_KEY"),
Endpoint: "http://localhost:9000",
}
s3Client, err := minio.New(config)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
bucketname := "restictestbucket"
err = s3Client.MakeBucket(bucketname, "")
if err != nil {
t.Fatal(err)
}
s, err := bes3.Open("127.0.0.1:9000", bucketname)
OK(t, err)
testBackend(s, t) testBackend(s, t)
} }