2015-05-15 21:53:00 +00:00
|
|
|
package backend_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2015-08-26 11:25:05 +00:00
|
|
|
"gopkg.in/amz.v3/aws"
|
|
|
|
"gopkg.in/amz.v3/s3"
|
|
|
|
"gopkg.in/amz.v3/s3/s3test"
|
2015-05-15 21:53:00 +00:00
|
|
|
|
|
|
|
bes3 "github.com/restic/restic/backend/s3"
|
|
|
|
. "github.com/restic/restic/test"
|
|
|
|
)
|
|
|
|
|
2015-05-16 11:48:55 +00:00
|
|
|
type LocalServer struct {
|
|
|
|
auth aws.Auth
|
|
|
|
region aws.Region
|
|
|
|
srv *s3test.Server
|
|
|
|
config *s3test.Config
|
|
|
|
}
|
|
|
|
|
|
|
|
var s LocalServer
|
2015-05-15 21:53:00 +00:00
|
|
|
|
2015-06-14 13:43:47 +00:00
|
|
|
func setupS3Backend(t *testing.T) *bes3.S3Backend {
|
2015-05-16 11:48:55 +00:00
|
|
|
s.config = &s3test.Config{
|
|
|
|
Send409Conflict: true,
|
|
|
|
}
|
|
|
|
srv, err := s3test.NewServer(s.config)
|
2015-05-15 21:53:00 +00:00
|
|
|
OK(t, err)
|
2015-05-16 11:48:55 +00:00
|
|
|
s.srv = srv
|
2015-05-15 21:53:00 +00:00
|
|
|
|
2015-05-16 11:48:55 +00:00
|
|
|
s.region = aws.Region{
|
|
|
|
Name: "faux-region-1",
|
|
|
|
S3Endpoint: srv.URL(),
|
|
|
|
S3LocationConstraint: true, // s3test server requires a LocationConstraint
|
|
|
|
}
|
2015-05-15 21:53:00 +00:00
|
|
|
|
2015-08-26 12:44:00 +00:00
|
|
|
s.auth = aws.Auth{"abc", "123"}
|
2015-05-15 21:53:00 +00:00
|
|
|
|
2015-05-16 11:48:55 +00:00
|
|
|
service := s3.New(s.auth, s.region)
|
2015-08-26 12:44:00 +00:00
|
|
|
bucket, berr := service.Bucket("testbucket")
|
2015-08-26 12:54:39 +00:00
|
|
|
OK(t, berr)
|
2015-05-16 11:48:55 +00:00
|
|
|
err = bucket.PutBucket("private")
|
|
|
|
OK(t, err)
|
|
|
|
|
|
|
|
t.Logf("created s3 backend locally")
|
2015-05-15 21:53:00 +00:00
|
|
|
|
2015-05-16 11:48:55 +00:00
|
|
|
return bes3.OpenS3Bucket(bucket, "testbucket")
|
2015-05-15 21:53:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestS3Backend(t *testing.T) {
|
|
|
|
s := setupS3Backend(t)
|
|
|
|
|
|
|
|
testBackend(s, t)
|
|
|
|
}
|