@@ -6,7 +6,7 @@ TEST(S3, ListObjectsBucket) {
66 try {
77 // Assuming the bucket has the 10K objects
88 // Once we implement PutObject we will do this ourselves with s3cpp
9- std::expected<ListBucketResult, ErrorNoSuchBucket > res = client.ListObjects (" my-bucket" );
9+ std::expected<ListBucketResult, Error > res = client.ListObjects (" my-bucket" );
1010 if (!res)
1111 GTEST_FAIL ();
1212 EXPECT_EQ (res->Contents .size (), 0 );
@@ -22,10 +22,10 @@ TEST(S3, ListObjectsBucket) {
2222TEST (S3, ListObjectsBucketNotExists) {
2323 S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000" , S3AddressingStyle::PathStyle);
2424 try {
25- std::expected<ListBucketResult, ErrorNoSuchBucket > res = client.ListObjects (" Does-not-exist" );
25+ std::expected<ListBucketResult, Error > res = client.ListObjects (" Does-not-exist" );
2626 if (res.has_value ()) // We must return error
2727 GTEST_FAIL ();
28- ErrorNoSuchBucket error = res.error ();
28+ Error error = res.error ();
2929 // EXPECT_EQ(error.Code, "InvalidBucketName");
3030 } catch (const std::exception& e) {
3131 const std::string emsg = e.what ();
@@ -40,7 +40,7 @@ TEST(S3, ListObjectsFilePrefix) {
4040 S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000" , S3AddressingStyle::PathStyle);
4141 try {
4242 // path/to/file_1.txt must exist
43- std::expected<ListBucketResult, ErrorNoSuchBucket > res = client.ListObjects (" my-bucket" , " path/to/file_1.txt" );
43+ std::expected<ListBucketResult, Error > res = client.ListObjects (" my-bucket" , " path/to/file_1.txt" );
4444 if (!res)
4545 GTEST_FAIL ();
4646 EXPECT_EQ (res->Contents .size (), 1 );
@@ -57,7 +57,7 @@ TEST(S3, ListObjectsDirPrefix) {
5757 S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000" , S3AddressingStyle::PathStyle);
5858 try {
5959 // Get 100 keys
60- std::expected<ListBucketResult, ErrorNoSuchBucket > res = client.ListObjects (" my-bucket" , " path/to/" , 100 );
60+ std::expected<ListBucketResult, Error > res = client.ListObjects (" my-bucket" , " path/to/" , 100 );
6161 if (!res)
6262 GTEST_FAIL ();
6363 EXPECT_EQ (res->Contents .size (), 100 );
@@ -73,7 +73,7 @@ TEST(S3, ListObjectsDirPrefix) {
7373TEST (S3, ListObjectsDirPrefixMaxKeys) {
7474 S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000" , S3AddressingStyle::PathStyle);
7575 try {
76- std::expected<ListBucketResult, ErrorNoSuchBucket > res = client.ListObjects (" my-bucket" , " path/to/" , 1 );
76+ std::expected<ListBucketResult, Error > res = client.ListObjects (" my-bucket" , " path/to/" , 1 );
7777 if (!res)
7878 GTEST_FAIL ();
7979 EXPECT_EQ (res->Contents .size (), 1 );
@@ -89,7 +89,7 @@ TEST(S3, ListObjectsDirPrefixMaxKeys) {
8989TEST (S3, ListObjectsCheckFields) {
9090 S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000" , S3AddressingStyle::PathStyle);
9191 try {
92- std::expected<ListBucketResult, ErrorNoSuchBucket > res = client.ListObjects (" my-bucket" , " path/to/" , 2 );
92+ std::expected<ListBucketResult, Error > res = client.ListObjects (" my-bucket" , " path/to/" , 2 );
9393 if (!res)
9494 GTEST_FAIL ();
9595
@@ -123,7 +123,7 @@ TEST(S3, ListObjectsCheckLenKeys) {
123123 S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000" , S3AddressingStyle::PathStyle);
124124 try {
125125 // has 10K objects - limit is 1000 keys
126- std::expected<ListBucketResult, ErrorNoSuchBucket > res = client.ListObjects (" my-bucket" , " path/to/" );
126+ std::expected<ListBucketResult, Error > res = client.ListObjects (" my-bucket" , " path/to/" );
127127 if (!res)
128128 GTEST_FAIL ();
129129 EXPECT_EQ (res->Contents .size (), 1000 );
@@ -146,7 +146,7 @@ TEST(S3, ListObjectsPaginator) {
146146 int pageCount = 0 ;
147147
148148 while (paginator.HasMorePages ()) {
149- std::expected<ListBucketResult, ErrorNoSuchBucket > page = paginator.NextPage ();
149+ std::expected<ListBucketResult, Error > page = paginator.NextPage ();
150150 if (!page) {
151151 GTEST_FAIL ();
152152 }
@@ -186,3 +186,37 @@ TEST(S3, GetObjectExists) {
186186 throw ;
187187 }
188188}
189+
190+ TEST (S3, GetObjectNotExists) {
191+ S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000" , S3AddressingStyle::PathStyle);
192+ try {
193+ auto response = client.GetObject (" my-bucket" , " does/not/exists.txt" );
194+ if (response) { // should trigger error
195+ GTEST_FAIL ();
196+ }
197+ EXPECT_EQ (response.error ().Code , " NoSuchKey" );
198+ } catch (const std::exception& e) {
199+ const std::string emsg = e.what ();
200+ if (emsg == " libcurl error: Could not connect to server" || emsg == " libcurl error: Couldn't connect to server" ) {
201+ GTEST_SKIP_ (" Skipping GetObjectNotExists: Server not up" );
202+ }
203+ throw ;
204+ }
205+ }
206+
207+ TEST (S3, GetObjectBadBucket) {
208+ S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000" , S3AddressingStyle::PathStyle);
209+ try {
210+ auto response = client.GetObject (" does-not-exist" , " path/to/file_1.txt" );
211+ if (response) { // should trigger error
212+ GTEST_FAIL ();
213+ }
214+ EXPECT_EQ (response.error ().Code , " NoSuchBucket" );
215+ } catch (const std::exception& e) {
216+ const std::string emsg = e.what ();
217+ if (emsg == " libcurl error: Could not connect to server" || emsg == " libcurl error: Couldn't connect to server" ) {
218+ GTEST_SKIP_ (" Skipping GetObjectExists: Server not up" );
219+ }
220+ throw ;
221+ }
222+ }
0 commit comments