test: use ipv4 instead of ipv6

Change-Id: Idc8251bceca768fc2d1048c1fa616c86fdc9861f
This commit is contained in:
scriptis 2024-10-30 15:48:31 -05:00
parent c95b73d8a1
commit 6d29b5538f

View file

@ -37,7 +37,7 @@ namespace nix {
static std::tuple<uint16_t, AutoCloseFD>
serveHTTP(std::vector<Reply> replies)
{
AutoCloseFD listener(::socket(AF_INET6, SOCK_STREAM, 0));
AutoCloseFD listener(::socket(AF_INET, SOCK_STREAM, 0));
if (!listener) {
throw SysError(errno, "socket() failed");
}
@ -46,7 +46,7 @@ serveHTTP(std::vector<Reply> replies)
trigger.create();
sockaddr_in6 addr = {
.sin6_family = AF_INET6,
.sin6_family = AF_INET,
.sin6_addr = IN6ADDR_LOOPBACK_INIT,
};
socklen_t len = sizeof(addr);
@ -155,7 +155,7 @@ TEST(FileTransfer, exceptionAbortsRead)
auto [port, srv] = serveHTTP("200 ok", "content-length: 0\r\n", [] { return ""; });
auto ft = makeFileTransfer();
char buf[10] = "";
ASSERT_THROW(ft->download(fmt("http://[::1]:%d/index", port)).second->read(buf, 10), EndOfFile);
ASSERT_THROW(ft->download(fmt("http://127.0.0.1:%d/index", port)).second->read(buf, 10), EndOfFile);
}
TEST(FileTransfer, NOT_ON_DARWIN(reportsSetupErrors))
@ -163,7 +163,7 @@ TEST(FileTransfer, NOT_ON_DARWIN(reportsSetupErrors))
auto [port, srv] = serveHTTP("404 not found", "", [] { return ""; });
auto ft = makeFileTransfer();
ASSERT_THROW(
ft->download(fmt("http://[::1]:%d/index", port)),
ft->download(fmt("http://127.0.0.1:%d/index", port)),
FileTransferError
);
}
@ -179,7 +179,7 @@ TEST(FileTransfer, NOT_ON_DARWIN(defersFailures))
return std::string(1024 * 1024, ' ');
});
auto ft = makeFileTransfer(0);
auto src = ft->download(fmt("http://[::1]:%d/index", port)).second;
auto src = ft->download(fmt("http://127.0.0.1:%d/index", port)).second;
ASSERT_THROW(src->drain(), FileTransferError);
}
@ -192,7 +192,7 @@ TEST(FileTransfer, NOT_ON_DARWIN(handlesContentEncoding))
auto ft = makeFileTransfer();
StringSink sink;
ft->download(fmt("http://[::1]:%d/index", port)).second->drainInto(sink);
ft->download(fmt("http://127.0.0.1:%d/index", port)).second->drainInto(sink);
EXPECT_EQ(sink.s, original);
}
@ -215,7 +215,7 @@ TEST(FileTransfer, usesIntermediateLinkHeaders)
{"200 ok", "content-length: 1\r\n", [] { return "a"; }},
});
auto ft = makeFileTransfer(0);
auto [result, _data] = ft->download(fmt("http://[::1]:%d/first", port));
auto [result, _data] = ft->download(fmt("http://127.0.0.1:%d/first", port));
ASSERT_EQ(result.immutableUrl, "http://foo");
}