22#include < s3cpp/s3.h>
33
44TEST (S3, ListObjectsNoPrefix) {
5- S3Client client (" minio_access" , " minio_secret" );
5+ S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000 " , S3AddressingStyle::PathStyle );
66 try {
7- client.ListObjects (" my-bucket" );
7+ // Assuming the bucket has the 10K objects
8+ // Once we implement PutObject we will do this ourselves with s3cpp
9+ ListBucketResult res = client.ListObjects (" my-bucket" );
10+ EXPECT_EQ (res.Contents .size (), 0 );
811 } catch (const std::exception& e) {
912 const std::string emsg = e.what ();
1013 if (emsg == " libcurl error: Could not connect to server" || emsg == " libcurl error: Couldn't connect to server" ) {
@@ -15,9 +18,11 @@ TEST(S3, ListObjectsNoPrefix) {
1518}
1619
1720TEST (S3, ListObjectsFilePrefix) {
18- S3Client client (" minio_access" , " minio_secret" );
21+ S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000 " , S3AddressingStyle::PathStyle );
1922 try {
20- client.ListObjects (" my-bucket" , " path/to/file.txt" );
23+ // path/to/file_1.txt must exist
24+ ListBucketResult res = client.ListObjects (" my-bucket" , " path/to/file_1.txt" );
25+ EXPECT_EQ (res.Contents .size (), 1 );
2126 } catch (const std::exception& e) {
2227 const std::string emsg = e.what ();
2328 if (emsg == " libcurl error: Could not connect to server" || emsg == " libcurl error: Couldn't connect to server" ) {
@@ -28,9 +33,11 @@ TEST(S3, ListObjectsFilePrefix) {
2833}
2934
3035TEST (S3, ListObjectsDirPrefix) {
31- S3Client client (" minio_access" , " minio_secret" );
36+ S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000 " , S3AddressingStyle::PathStyle );
3237 try {
33- client.ListObjects (" my-bucket" , " path/to/" , 100 );
38+ // Get 100 keys
39+ ListBucketResult res = client.ListObjects (" my-bucket" , " path/to/" , 100 );
40+ EXPECT_EQ (res.Contents .size (), 100 );
3441 } catch (const std::exception& e) {
3542 const std::string emsg = e.what ();
3643 if (emsg == " libcurl error: Could not connect to server" || emsg == " libcurl error: Couldn't connect to server" ) {
@@ -41,9 +48,10 @@ TEST(S3, ListObjectsDirPrefix) {
4148}
4249
4350TEST (S3, ListObjectsDirPrefixMaxKeys) {
44- S3Client client (" minio_access" , " minio_secret" );
51+ S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000 " , S3AddressingStyle::PathStyle );
4552 try {
46- client.ListObjects (" my-bucket" , " path/to/" , 1 );
53+ ListBucketResult res = client.ListObjects (" my-bucket" , " path/to/" , 1 );
54+ EXPECT_EQ (res.Contents .size (), 1 );
4755 } catch (const std::exception& e) {
4856 const std::string emsg = e.what ();
4957 if (emsg == " libcurl error: Could not connect to server" || emsg == " libcurl error: Couldn't connect to server" ) {
@@ -54,30 +62,27 @@ TEST(S3, ListObjectsDirPrefixMaxKeys) {
5462}
5563
5664TEST (S3, ListObjectsCheckFields) {
57- S3Client client (" minio_access" , " minio_secret" );
65+ S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000 " , S3AddressingStyle::PathStyle );
5866 try {
59- ListBucketResult response = client.ListObjects (" my-bucket" , " path/to/" , 2 );
60-
61- // Check top-level fields
62- EXPECT_EQ (response.Name , " my-bucket" );
63- EXPECT_EQ (response.Prefix , " path/to/" );
64- EXPECT_EQ (response.MaxKeys , 2 );
65- EXPECT_EQ (response.IsTruncated , true );
66- EXPECT_FALSE (response.NextContinuationToken .empty ()); // V2 uses NextContinuationToken
67-
68- // Should have exactly 2 contents
69- EXPECT_EQ (response.Contents .size (), 2 );
70-
71- // Check first object
72- EXPECT_EQ (response.Contents [0 ].Key , " path/to/file_1.txt" );
73- EXPECT_EQ (response.Contents [0 ].Size , 26 );
74- // Note: V2 doesn't return Owner by default (need fetch-owner=true)
75- EXPECT_EQ (response.Contents [0 ].StorageClass , " STANDARD" );
76-
77- // Check second object
78- EXPECT_EQ (response.Contents [1 ].Key , " path/to/file_10.txt" );
79- EXPECT_EQ (response.Contents [1 ].Size , 27 );
80- EXPECT_EQ (response.Contents [1 ].StorageClass , " STANDARD" );
67+ ListBucketResult res = client.ListObjects (" my-bucket" , " path/to/" , 2 );
68+
69+ EXPECT_EQ (res.Name , " my-bucket" );
70+ EXPECT_EQ (res.Prefix , " path/to/" );
71+ EXPECT_EQ (res.MaxKeys , 2 );
72+ EXPECT_EQ (res.IsTruncated , true );
73+ EXPECT_FALSE (res.NextContinuationToken .empty ());
74+
75+ // Should have exactly 2 keys
76+ EXPECT_EQ (res.Contents .size (), 2 );
77+
78+ EXPECT_EQ (res.Contents [0 ].Key , " path/to/file_1.txt" );
79+ EXPECT_EQ (res.Contents [0 ].Size , 26 );
80+ EXPECT_EQ (res.Contents [0 ].StorageClass , " STANDARD" );
81+
82+ EXPECT_EQ (res.Contents [1 ].Key , " path/to/file_10.txt" );
83+ EXPECT_EQ (res.Contents [1 ].Size , 27 );
84+ EXPECT_EQ (res.Contents [1 ].StorageClass , " STANDARD" );
85+
8186 } catch (const std::exception& e) {
8287 const std::string emsg = e.what ();
8388 if (emsg == " libcurl error: Could not connect to server" || emsg == " libcurl error: Couldn't connect to server" ) {
@@ -88,11 +93,11 @@ TEST(S3, ListObjectsCheckFields) {
8893}
8994
9095TEST (S3, ListObjectsCheckLenKeys) {
91- S3Client client (" minio_access" , " minio_secret" );
96+ S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000 " , S3AddressingStyle::PathStyle );
9297 try {
93- // has 10K objects - limit is 1000 keys
98+ // has 10K objects - limit is 1000 keys
9499 ListBucketResult response = client.ListObjects (" my-bucket" , " path/to/" );
95- EXPECT_EQ (response.Contents .size (), 1000 );
100+ EXPECT_EQ (response.Contents .size (), 1000 );
96101 } catch (const std::exception& e) {
97102 const std::string emsg = e.what ();
98103 if (emsg == " libcurl error: Could not connect to server" || emsg == " libcurl error: Couldn't connect to server" ) {
@@ -103,7 +108,7 @@ TEST(S3, ListObjectsCheckLenKeys) {
103108}
104109
105110TEST (S3, ListObjectsPaginator) {
106- S3Client client (" minio_access" , " minio_secret" );
111+ S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000 " , S3AddressingStyle::PathStyle );
107112 try {
108113 // has 10K objects - fetch 100 per page
109114 ListObjectsPaginator paginator (client, " my-bucket" , " path/to/" , 100 );
@@ -114,7 +119,8 @@ TEST(S3, ListObjectsPaginator) {
114119 while (paginator.HasMorePages ()) {
115120 ListBucketResult page = paginator.NextPage ();
116121 totalObjects += page.Contents .size ();
117- pageCount++;
122+ if (page.Contents .size () > 0 )
123+ pageCount++;
118124
119125 if (paginator.HasMorePages ()) {
120126 EXPECT_EQ (page.Contents .size (), 100 );
@@ -127,7 +133,20 @@ TEST(S3, ListObjectsPaginator) {
127133 } catch (const std::exception& e) {
128134 const std::string emsg = e.what ();
129135 if (emsg == " libcurl error: Could not connect to server" || emsg == " libcurl error: Couldn't connect to server" ) {
130- GTEST_SKIP_ (" Skipping MinIOBasicRequest: Server not up" );
136+ GTEST_SKIP_ (" Skipping ListObjectsPaginator: Server not up" );
137+ }
138+ throw ;
139+ }
140+ }
141+
142+ TEST (S3, GetObjectExists) {
143+ S3Client client (" minio_access" , " minio_secret" , " 127.0.0.1:9000" , S3AddressingStyle::PathStyle);
144+ try {
145+ ListBucketResult response = client.GetObject (" my-bucket" , " path/to/file_1.txt" );
146+ } catch (const std::exception& e) {
147+ const std::string emsg = e.what ();
148+ if (emsg == " libcurl error: Could not connect to server" || emsg == " libcurl error: Couldn't connect to server" ) {
149+ GTEST_SKIP_ (" Skipping GetObjectExists: Server not up" );
131150 }
132151 throw ;
133152 }
0 commit comments