Пример #1
0
// Start starts server used for MockS3
func (s *MockS3) Start(t *testing.T) {
	srv, err := s3test.NewServer(s.config)
	ensure.Nil(t, err)
	ensure.NotNil(t, srv)

	s.srv = srv
	s.region = aws.Region{
		Name:                 "faux-region-1",
		S3Endpoint:           srv.URL(),
		S3LocationConstraint: true, // s3test server requires a LocationConstraint
	}
}
Пример #2
0
func (s *LocalServer) SetUp(c *check.C) {
	srv, err := s3test.NewServer(s.config)
	c.Assert(err, check.IsNil)
	c.Assert(srv, check.NotNil)

	s.srv = srv
	s.region = aws.Region{
		Name:                 "faux-region-1",
		S3Endpoint:           srv.URL(),
		S3LocationConstraint: true, // s3test server requires a LocationConstraint
	}
}
Пример #3
0
func runTest(t *testing.T, testfunc func(t *testing.T, src, dst *Bucket)) {
	server, err := s3test.NewServer(nil)

	if err != nil {
		t.Fatalf("Cannot start test S3 server: %s", err)
	}

	defer server.Quit()

	config := aws.NewConfig()
	config.Credentials = credentials.NewStaticCredentials("xx", "yy", "zz")
	config.DisableSSL = aws.Bool(false)
	config.Endpoint = aws.String(server.URL())
	config.Region = aws.String("us-east-1")
	config.S3ForcePathStyle = aws.Bool(true)

	srcBucketName := fmt.Sprintf("test-%d-src", testIdx)
	dstBucketName := fmt.Sprintf("test-%d-dst", testIdx)
	testIdx++

	s3client := s3.New(config)

	for _, bucketName := range []string{srcBucketName, dstBucketName} {
		req := s3.CreateBucketInput{
			Bucket: aws.String(bucketName),
			CreateBucketConfiguration: &s3.CreateBucketConfiguration{
				LocationConstraint: aws.String("us-east-1"),
			},
		}

		_, err := s3client.CreateBucket(&req)

		if err != nil {
			t.Fatalf("Error while creating bucket %s: %s", bucketName, err)
		}
	}

	srcBucket := Bucket{
		Name:   srcBucketName,
		Client: s3client,
	}

	dstBucket := Bucket{
		Name:   dstBucketName,
		Client: s3client,
	}

	testfunc(t, &srcBucket, &dstBucket)
}
Пример #4
0
func NewTestableS3Volume(c *check.C, readonly bool, replication int) *TestableS3Volume {
	clock := &fakeClock{}
	srv, err := s3test.NewServer(&s3test.Config{Clock: clock})
	c.Assert(err, check.IsNil)
	auth := aws.Auth{}
	region := aws.Region{
		Name:                 "test-region-1",
		S3Endpoint:           srv.URL(),
		S3LocationConstraint: true,
	}
	bucket := &s3.Bucket{
		S3:   s3.New(auth, region),
		Name: TestBucketName,
	}
	err = bucket.PutBucket(s3.ACL("private"))
	c.Assert(err, check.IsNil)

	return &TestableS3Volume{
		S3Volume:    NewS3Volume(auth, region, TestBucketName, readonly, replication),
		server:      srv,
		serverClock: clock,
	}
}