Files
mtusi2026lab4/tools/s3_smoke.cpp
T
2026-10-30 21:09:56 +03:00

36 lines
1003 B
C++

// Small smoke tool for step 4: put → get → delete against MinIO.
#include "s3_client.hpp"
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
int main() {
try {
auto cfg = S3Client::from_env();
S3Client s3(cfg);
const std::string key = "smoke/step4.txt";
const std::string payload = "lab4-s3-smoke-ok";
std::istringstream in(payload);
s3.put_object(key, in, static_cast<std::int64_t>(payload.size()),
"text/plain");
std::ostringstream out;
s3.get_object(key, out);
if (out.str() != payload) {
std::cerr << "mismatch: got [" << out.str() << "]\n";
return 2;
}
s3.delete_object(key);
std::cout << "s3_smoke: OK bucket=" << cfg.bucket << " key=" << key << "\n";
return 0;
} catch (const std::exception& e) {
std::cerr << "s3_smoke: FAIL: " << e.what() << "\n";
return 1;
}
}