Пример #1
0
func killBucket(b *s3.Bucket) {
	var err error
	for attempt := attempts.Start(); attempt.Next(); {
		err = b.DelBucket()
		if err == nil {
			return
		}
		if _, ok := err.(*net.DNSError); ok {
			return
		}
		e, ok := err.(*s3.Error)
		if ok && e.Code == "NoSuchBucket" {
			return
		}
		if ok && e.Code == "BucketNotEmpty" {
			// Errors are ignored here. Just retry.
			resp, err := b.List("", "", "", 1000)
			if err == nil {
				for _, key := range resp.Contents {
					_ = b.Del(key.Key)
				}
			}
			multis, _, _ := b.ListMulti("", "")
			for _, m := range multis {
				_ = m.Abort()
			}
		}
	}
	message := "cannot delete test bucket"
	if err != nil {
		message += ": " + err.Error()
	}
	panic(message)
}
Пример #2
0
		Context("when the bucket already exists", func() {
			var (
				err    error
				bucket s3.Bucket
			)

			BeforeEach(func() {
				err := goamzBucketClient.PutBucket(goamz.BucketOwnerFull)
				Expect(err).NotTo(HaveOccurred())

				client := s3.NewClient(fakeS3EndpointURL, "accessKey", "secretKey", logger)
				bucket, err = client.GetOrCreateBucket(bucketName)
			})

			AfterEach(func() {
				err := goamzBucketClient.DelBucket()
				Expect(err).NotTo(HaveOccurred())
			})

			It("returns the bucket", func() {
				Expect(bucket.Name()).To(Equal(bucketName))
			})

			It("does not return an error", func() {
				Expect(err).NotTo(HaveOccurred())
			})

			It("provides logging", func() {
				Expect(log).To(gbytes.Say(
					fmt.Sprintf(`{"bucket_name":"%s","event":"starting"}`, bucketName),
				))