Skip to content

Commit

Permalink
ft: BKTCLT-32 go client DeleteBucket
Browse files Browse the repository at this point in the history
Implement the DeleteBucket API call, which calls the bucketd route
`DELETE /default/bucket/{bucketname}`.
  • Loading branch information
jonathan-gramain committed Oct 22, 2024
1 parent d2f8752 commit e59aa3a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions go/deletebucket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package bucketclient

import (
"context"
"fmt"
)

// DeleteBucket deletes a bucket entry from metadata.
func (client *BucketClient) DeleteBucket(ctx context.Context, bucketName string) error {
resource := fmt.Sprintf("/default/bucket/%s", bucketName)

_, err := client.Request(ctx, "DeleteBucket", "DELETE", resource)
return err
}
32 changes: 32 additions & 0 deletions go/deletebucket_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package bucketclient_test

import (
"net/http"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/jarcoal/httpmock"

"github.com/scality/bucketclient/go"
)

var _ = Describe("DeleteBucket()", func() {
It("deletes an existing bucket entry", func(ctx SpecContext) {
httpmock.RegisterResponder("DELETE", "/default/bucket/my-bucket",
httpmock.NewStringResponder(200, ""))

Expect(client.DeleteBucket(ctx, "my-bucket")).To(Succeed())
})

It("forwards a 404 NotFound error when the bucket doesn't exist", func(ctx SpecContext) {
httpmock.RegisterResponder("DELETE", "/default/bucket/my-bucket",
httpmock.NewStringResponder(http.StatusNotFound, ""))

err := client.DeleteBucket(ctx, "my-bucket")
Expect(err).To(HaveOccurred())
bcErr, ok := err.(*bucketclient.BucketClientError)
Expect(ok).To(BeTrue())
Expect(bcErr.StatusCode).To(Equal(http.StatusNotFound))
})
})

0 comments on commit e59aa3a

Please sign in to comment.