userver: /data/code/userver/libraries/s3api/src/s3api/s3api_methods_test.cpp Source File
Loading...
Searching...
No Matches
s3api_methods_test.cpp
2
3#include <fmt/format.h>
4
5#include <userver/http/common_headers.hpp>
6#include <userver/utest/utest.hpp>
7#include <userver/utils/algo.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace s3api::api_methods {
12
13TEST(S3ApiMethods, CopyObject) {
14 const std::string source_bucket = "source_bucket";
15 const std::string source_key = "source_key";
16 const std::string dest_bucket = "dest_bucket";
17 const std::string dest_key = "dest_key";
18 const std::string content_type = "application/json";
19
20 const Request request = CopyObject(source_bucket, source_key, dest_bucket, dest_key, content_type);
21 EXPECT_EQ(request.method, USERVER_NAMESPACE::clients::http::HttpMethod::kPut);
22 EXPECT_EQ(request.req, dest_key);
23 EXPECT_EQ(request.bucket, dest_bucket);
24 EXPECT_TRUE(request.body.empty());
25 const std::string* copy_source = USERVER_NAMESPACE::utils::FindOrNullptr(request.headers, headers::kAmzCopySource);
26 ASSERT_NE(copy_source, nullptr);
27 EXPECT_EQ(*copy_source, fmt::format("/{}/{}", source_bucket, source_key));
28}
29
30TEST(S3ApiMethods, GetObjectWithRange) {
31 const std::string bucket = "bucket";
32 const std::string path = "path";
33 const std::optional<std::string_view> version = "version";
34 Request request = GetObject(bucket, path, version);
35 SetRange(request, "Range: bytes=0-100");
36 const std::string expected_value = "Range: bytes=0-100";
37 EXPECT_STREQ(
38 USERVER_NAMESPACE::utils::FindOrNullptr(request.headers, USERVER_NAMESPACE::http::headers::kRange)->c_str(),
39 expected_value.c_str()
40 );
41}
42
43} // namespace s3api::api_methods
44
45USERVER_NAMESPACE_END