From 69a9adc4c3575a8108002fc08601ffa7af7aa6b1 Mon Sep 17 00:00:00 2001 From: Chris Howey Date: Sat, 7 Nov 2015 06:43:15 -0600 Subject: [PATCH] Use local instance of minio server. Need to figure out how to have tests automatically start and kill server. --- Godeps/Godeps.json | 3 +-- backend/s3/s3.go | 32 ++++++++------------------------ backend/s3_test.go | 21 +++++++++++++++++++-- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 01bcb29b5..b818dc01e 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -24,8 +24,7 @@ }, { "ImportPath": "github.com/minio/minio-go", - "Comment": "v0.2.5-58-g5c3a491", - "Rev": "5c3a4919116141f088990bd6ee385877648c7a25" + "Rev": "61f6570da0edd761974216c9ed5da485d3cc0c99" }, { "ImportPath": "github.com/pkg/sftp", diff --git a/backend/s3/s3.go b/backend/s3/s3.go index b5b7895fb..35c44a55a 100644 --- a/backend/s3/s3.go +++ b/backend/s3/s3.go @@ -3,9 +3,7 @@ package s3 import ( "bytes" "errors" - "fmt" "io" - "io/ioutil" "os" "strings" @@ -48,7 +46,11 @@ func Open(regionname, bucketname string) (backend.Backend, error) { } } else { // S3 compatible endpoint - config.Endpoint = "https://" + regionname + if strings.Contains(regionname, "localhost") || strings.Contains(regionname, "127.0.0.1") { + config.Endpoint = "http://" + regionname + } else { + config.Endpoint = "https://" + regionname + } } s3api, s3err := minio.New(config) @@ -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 // 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) { - rc, err := be.Get(t, name) - if err != nil { - return nil, 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 + path := s3path(t, name) + rc, _, err := be.s3api.GetPartialObject(be.bucketname, path, int64(offset), int64(length)) + return rc, err } // Test returns true if a blob of the given type and name exists in the backend. diff --git a/backend/s3_test.go b/backend/s3_test.go index cf1aeaa1c..dbcfb3c4b 100644 --- a/backend/s3_test.go +++ b/backend/s3_test.go @@ -1,17 +1,34 @@ package backend_test import ( + "os" "testing" + "github.com/minio/minio-go" bes3 "github.com/restic/restic/backend/s3" + . "github.com/restic/restic/test" ) 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 { 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) }