-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft: BKTCLT-32 go client DeleteBucket
Implement the DeleteBucket API call, which calls the bucketd route `DELETE /default/bucket/{bucketname}`.
- Loading branch information
1 parent
d2f8752
commit e59aa3a
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) | ||
}) |