diff options
author | Pierre Bourdon <delroth@gmail.com> | 2024-05-11 15:10:45 +0200 |
---|---|---|
committer | Pierre Bourdon <delroth@gmail.com> | 2024-05-11 15:58:32 +0200 |
commit | a30c5673367533aec48faa59dd0d76b283dda1ba (patch) | |
tree | 3f644e1440e551ea9c6af2505448ac425a8a7cca /tests/unit | |
parent | 38d825b21e425b0f0a64304ff5bfe4dfbeaf9e97 (diff) |
filetransfer: unit test content-encoding handling
Very basic behavior test to ensure that gzip data gets internally
decompressed by the file transfer pipeline.
Change a std::string_view return value in the test harness to
std::string. I wouldn't call myself a C++ beginner and I still managed
to shoot myself in the foot like three times with the lifetime
managements there (e.g. [&] { return an_std_string; } ends up with a
dangling string_view!).
Change-Id: I1360750d4181ce1ca2a3aa4dc0e97e131351c469
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/libstore/filetransfer.cc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/unit/libstore/filetransfer.cc b/tests/unit/libstore/filetransfer.cc index ebd38f19d..684697c69 100644 --- a/tests/unit/libstore/filetransfer.cc +++ b/tests/unit/libstore/filetransfer.cc @@ -1,4 +1,5 @@ #include "filetransfer.hh" +#include "compression.hh" #include <cstdint> #include <exception> @@ -25,7 +26,7 @@ using namespace std::chrono_literals; namespace nix { static std::tuple<uint16_t, AutoCloseFD> -serveHTTP(std::string_view status, std::string_view headers, std::function<std::string_view()> content) +serveHTTP(std::string_view status, std::string_view headers, std::function<std::string()> content) { AutoCloseFD listener(::socket(AF_INET6, SOCK_STREAM, 0)); if (!listener) { @@ -152,4 +153,17 @@ TEST(FileTransfer, NOT_ON_DARWIN(reportsTransferError)) req.baseRetryTimeMs = 0; ASSERT_THROW(ft->download(req), FileTransferError); } + +TEST(FileTransfer, NOT_ON_DARWIN(handlesContentEncoding)) +{ + std::string original = "Test data string"; + std::string compressed = compress("gzip", original); + + auto [port, srv] = serveHTTP("200 ok", "content-encoding: gzip\r\n", [&] { return compressed; }); + auto ft = makeFileTransfer(); + + StringSink sink; + ft->download(FileTransferRequest(fmt("http://[::1]:%d/index", port)), sink); + EXPECT_EQ(sink.s, original); +} } |