MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / putSpanBody

Method putSpanBody

Tests/Libraries/Http/HttpAsyncClientTest.cpp:790–863  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

788 {
789 SC_TEST_EXPECT(threadPool.create(2));
790 }
791 SC_TEST_EXPECT(httpServer.init(Span<ServerConnection>(connections)));
792 SC_TEST_EXPECT(httpServer.start(loop, "127.0.0.1", port));
793 SC_TEST_EXPECT(fileServer.init(threadPool, loop, webServerFolder));
794 struct ServerContext
795 {
796 HttpAsyncFileServer& fileServer;
797 HttpAsyncFileServer::StreamQueue<2>* streams;
798 } serverCtx = {fileServer, streams};
799 httpServer.onRequest = [this, &serverCtx](HttpConnection& connection)
800 {
801 SC_TEST_EXPECT(
802 serverCtx.fileServer.handleRequest(serverCtx.streams[connection.getConnectionID().getIndex()], connection));
803 };
804
805 ClientConnection clientStorage;
806 HttpAsyncClient client;
807 ResponseCollector collector;
808 TimeoutGuard timeout;
809 FileSystem fs;
810
811 String url = StringEncoding::Ascii;
812 struct Context
813 {
814 ResponseCollector& collector;
815 HttpAsyncServer& httpServer;
816 FileSystem& fs;
817 } ctx = {collector, httpServer, fs};
818
819 SC_TEST_EXPECT(fs.init(webServerFolder));
820 SC_TEST_EXPECT(client.init(clientStorage));
821 SC_TEST_EXPECT(StringBuilder::format(url, "http://127.0.0.1:{}/client-put-span.txt", port));
822
823 client.onResponse = [this, &ctx](HttpAsyncClientResponse& response)
824 {
825 ctx.collector.attach(response,
826 [this, &ctx](HttpAsyncClientResponse& completedResponse)
827 {
828 ctx.collector.detach();
829 SC_TEST_EXPECT(completedResponse.getParser().statusCode == 201);
830 String content;
831 SC_TEST_EXPECT(ctx.fs.read("client-put-span.txt", content));
832 SC_TEST_EXPECT(content == "InlineBody");
833 SC_TEST_EXPECT(ctx.fs.removeFile("client-put-span.txt"));
834 SC_TEST_EXPECT(ctx.httpServer.stop());
835 });
836 };
837 client.onError = [this](Result result) { SC_TEST_EXPECT(result); };
838
839 SC_TEST_EXPECT(timeout.start(loop, TimeMs{2000}));
840 SC_TEST_EXPECT(client.put(loop, url.view(), StringSpan("InlineBody")));
841 SC_TEST_EXPECT(loop.run());
842 SC_TEST_EXPECT(fileServer.close());
843 SC_TEST_EXPECT(httpServer.close());
844 SC_TEST_EXPECT(loop.close());
845}
846
847void SC::HttpAsyncClientTest::requestOptions()

Callers

nothing calls this directly

Calls 15

StringSpanFunction · 0.85
mapPortMethod · 0.80
formatFunction · 0.50
viewMethod · 0.45
createMethod · 0.45
initMethod · 0.45
startMethod · 0.45
handleRequestMethod · 0.45
attachMethod · 0.45
detachMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected