Skip to content

Commit f6ff11e

Browse files
committed
Implement tests for DeleteBucket with empty and non-empty buckets with the paginator
1 parent 31b2af5 commit f6ff11e

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,45 @@ int main() {
124124
}
125125
```
126126
127+
Delete a non-empty bucket:
128+
129+
```cpp
130+
#include <s3cpp/s3.h>
131+
132+
int main() {
133+
S3Client client("minio_access", "minio_secret");
134+
135+
// To delete a bucket we first need to delete all its contents
136+
ListObjectsPaginator paginator(client, "my-bucket", "", 1000);
137+
138+
while (paginator.HasMorePages()) {
139+
auto page = paginator.NextPage();
140+
141+
if (!page) {
142+
std::println("Error listing objects: {}", page.error().Message);
143+
return 1;
144+
}
145+
146+
for (const auto& obj : page->Contents) {
147+
auto result = client.DeleteObject("my-bucket", obj.Key);
148+
if (!result) {
149+
std::println("Error deleting {}: {}", obj.Key, result.error().Message);
150+
return 1;
151+
}
152+
}
153+
}
154+
155+
auto result = client.DeleteBucket("my-bucket");
156+
if (!result) {
157+
std::println("Error deleting bucket: {}", result.error().Message);
158+
return 1;
159+
}
160+
161+
std::println("Bucket deleted successfully");
162+
return 0;
163+
}
164+
```
165+
127166
## Build and Test
128167

129168
```bash

0 commit comments

Comments
 (0)