mirror of
https://github.com/octoleo/restic.git
synced 2024-12-24 03:45:27 +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:
parent
e2445f4c97
commit
69a9adc4c3
3
Godeps/Godeps.json
generated
3
Godeps/Godeps.json
generated
@ -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",
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user