Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F140217
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
17 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e1cc3cf..882d9ae 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,156 +1,162 @@
# Do not let the option()s override variables here
cmake_minimum_required(VERSION 3.13)
if(NOT DEFINED PROJECT_NAME)
if(NOT DEFINED libkazv_INSTALL_HEADERS)
set(libkazv_INSTALL_HEADERS ON)
endif()
endif()
project(libkazv)
set(libkazvSourceRoot ${CMAKE_CURRENT_SOURCE_DIR})
set(libkazv_VERSION_MAJOR 0)
set(libkazv_VERSION_MINOR 2)
set(libkazv_VERSION_PATCH 1)
set(libkazv_VERSION_STRING ${libkazv_VERSION_MAJOR}.${libkazv_VERSION_MINOR}.${libkazv_VERSION_PATCH})
set(libkazv_SOVERSION 2)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
option(libkazv_BUILD_TESTS "Build tests" ON)
option(libkazv_BUILD_EXAMPLES "Build examples" ON)
option(libkazv_BUILD_KAZVJOB "Build libkazvjob the async and networking library" ON)
option(libkazv_OUTPUT_LEVEL "Output level: Debug>=90, Info>=70, Quiet>=20, no output=1" 0)
option(libkazv_ENABLE_COVERAGE "Enable code coverage information" OFF)
if(libkazv_ENABLE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fPIC -O0")
endif()
if((libkazv_BUILD_TESTS OR libkazv_BUILD_EXAMPLES) AND NOT libkazv_BUILD_KAZVJOB)
message(FATAL_ERROR
"You asked kazvjob not to be built, but asked to build tests or examples. Tests and examples both depend on kazvjob. This is not possible.")
endif()
+if(libkazv_BUILD_TESTS)
+ set(BUILD_TESTING ON)
+ include(CTest)
+ set(CMAKE_CTEST_ARGUMENTS --output-on-failure)
+endif()
+
# Build shared libraries by default
if(NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(LIBKAZV_BUILT_WITH_DEBUG 1)
else()
set(LIBKAZV_BUILT_WITH_DEBUG 0)
endif()
find_package(Boost REQUIRED COMPONENTS serialization)
include(FetchContent)
if(libkazv_BUILD_KAZVJOB)
find_package(cpr)
if (NOT cpr_FOUND)
message( STATUS "Using cpr from FetchContent")
set(USE_SYSTEM_CURL ON)
set(BUILD_CPR_TESTS OFF)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/whoshuu/cpr.git GIT_TAG c34ddb9b3de2a22fdbd5d318d8b7d1997e6ca0bf)
FetchContent_MakeAvailable(cpr)
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif()
if(libkazv_BUILD_TESTS)
find_package(Catch2)
if (NOT Catch2_FOUND)
message(STATUS "Using Catch2 from FetchContent")
FetchContent_Declare(Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2 GIT_TAG v2.13.0)
FetchContent_MakeAvailable(Catch2)
endif()
endif()
find_package(nlohmann_json)
if (NOT nlohmann_json_FOUND)
message(STATUS "Using nlohmann_json from FetchContent")
set(JSON_BuildTests OFF)
FetchContent_Declare(nlohmann_json GIT_REPOSITORY https://github.com/nlohmann/json GIT_TAG v3.9.1)
FetchContent_MakeAvailable(nlohmann_json)
endif()
find_package(Immer)
if(NOT Immer_FOUND)
message(STATUS "Using Immer from FetchContent")
set(immer_BUILD_TESTS OFF)
set(immer_BUILD_EXAMPLES OFF)
set(immer_BUILD_DOCS OFF)
set(immer_BUILD_EXTRAS OFF)
FetchContent_Declare(immer GIT_REPOSITORY https://github.com/arximboldi/immer GIT_TAG
800ddb04e528a3e83e69e8021d7e872e7c34cbcd)
FetchContent_MakeAvailable(immer)
endif()
find_package(Zug)
if(NOT Zug_FOUND)
message(STATUS "Using zug from FetchContent")
set(zug_BUILD_TESTS OFF)
set(zug_BUILD_EXAMPLES OFF)
set(zug_BUILD_DOCS OFF)
FetchContent_Declare(zug GIT_REPOSITORY https://github.com/arximboldi/zug GIT_TAG
266cc7fcc01f546c4fd0dabf3a26c71ddc7f3e7d)
FetchContent_MakeAvailable(zug)
endif()
find_package(Lager)
if(NOT Lager_FOUND)
message(STATUS "Using lager from FetchContent")
set(lager_BUILD_TESTS OFF)
set(lager_BUILD_EXAMPLES OFF)
set(lager_BUILD_DOCS OFF)
set(lager_EMBED_RESOURCES_PATH OFF)
FetchContent_Declare(lager GIT_REPOSITORY https://github.com/arximboldi/lager GIT_TAG
71eca6b0ebbccf3e0e54324b6967f047e49ba92d)
FetchContent_MakeAvailable(lager)
endif()
find_package(cryptopp REQUIRED)
find_package(Olm REQUIRED)
if(libkazv_BUILD_EXAMPLES)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBHTTPSERVER REQUIRED libhttpserver)
endif()
if(libkazv_OUTPUT_LEVEL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLIBKAZV_OUTPUT_LEVEL=${libkazv_OUTPUT_LEVEL}")
endif()
include(GNUInstallDirs)
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/libkazv)
add_subdirectory(src)
install(EXPORT libkazvTargets
NAMESPACE
libkazv::
DESTINATION
${ConfigPackageLocation}
)
install(
FILES cmake/libkazvConfig.cmake
DESTINATION ${ConfigPackageLocation})
# cpr does not install a good config file.
# We use the find module instead.
install(
FILES cmake/Findcpr.cmake
cmake/Findcryptopp.cmake
DESTINATION ${ConfigPackageLocation})
diff --git a/Dockerfile b/Dockerfile
index acd9b03..5d1582e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,21 +1,21 @@
FROM reg.lily.kazv.moe/kazv/libkazv-deps/deps:servant
RUN mkdir -pv /build
COPY . /build/libkazv
WORKDIR /build/libkazv
ARG BUILD_TYPE=Debug
ARG JOBS=3
ARG DEPS_INSTALL_DIR=/opt/libkazv-deps
ARG LIBKAZV_INSTALL_DIR=/opt/libkazv
RUN mkdir build && cd build && \
export CC=gcc-9 CXX=g++-9 && \
cmake .. -DCMAKE_INSTALL_PREFIX="$LIBKAZV_INSTALL_DIR" -DCMAKE_PREFIX_PATH="$DEPS_INSTALL_DIR" -DCMAKE_BUILD_TYPE=$BUILD_TYPE -Dlibkazv_BUILD_TESTS=ON -Dlibkazv_BUILD_EXAMPLES=ON -Dlibkazv_BUILD_KAZVJOB=ON && \
make -j$JOBS && \
- ./src/tests/kazvtest && \
+ make test && \
make -j$JOBS install && \
cd ../.. && \
rm -rf /build/libkazv
diff --git a/Dockerfile.cov b/Dockerfile.cov
index f352e94..3d88209 100644
--- a/Dockerfile.cov
+++ b/Dockerfile.cov
@@ -1,22 +1,22 @@
FROM reg.lily.kazv.moe/kazv/libkazv-deps/deps:servant
RUN mkdir -pv /build
COPY . /build/libkazv
WORKDIR /build/libkazv
ARG BUILD_TYPE=Debug
ARG JOBS=3
ARG DEPS_INSTALL_DIR=/opt/libkazv-deps
ARG LIBKAZV_INSTALL_DIR=/opt/libkazv
RUN mkdir build && cd build && \
export CC=gcc-9 CXX=g++-9 && \
cmake .. -DCMAKE_INSTALL_PREFIX="$LIBKAZV_INSTALL_DIR" -DCMAKE_PREFIX_PATH="$DEPS_INSTALL_DIR" -DCMAKE_BUILD_TYPE=$BUILD_TYPE -Dlibkazv_BUILD_TESTS=ON \
-Dlibkazv_BUILD_EXAMPLES=ON -Dlibkazv_BUILD_KAZVJOB=ON -Dlibkazv_ENABLE_COVERAGE=ON && \
make -j$JOBS && \
- ./src/tests/kazvtest && \
+ make test && \
gcovr -r ../src --object-directory src -e '.*/api/.*' && \
cd ../.. && \
rm -rf /build/libkazv
diff --git a/changelogs/35.fix b/changelogs/35.fix
new file mode 100644
index 0000000..f54a2b0
--- /dev/null
+++ b/changelogs/35.fix
@@ -0,0 +1 @@
+Do not run tests that require Internet in pipeline
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 5c0da22..c86019e 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -1,58 +1,60 @@
include(CTest)
set(KAZVTEST_RESPATH ${CMAKE_CURRENT_SOURCE_DIR}/resources)
configure_file(kazvtest-respath.hpp.in kazvtest-respath.hpp)
add_executable(kazvtest
testmain.cpp
basejobtest.cpp
event-test.cpp
cursorutiltest.cpp
base/serialization-test.cpp
base/types-test.cpp
base/immer-utils-test.cpp
client/client-test-util.cpp
client/discovery-test.cpp
client/sync-test.cpp
client/content-test.cpp
client/paginate-test.cpp
client/util-test.cpp
client/serialization-test.cpp
client/encrypted-file-test.cpp
client/sdk-test.cpp
client/thread-safety-test.cpp
client/room-test.cpp
client/random-generator-test.cpp
client/profile-test.cpp
client/kick-test.cpp
client/ban-test.cpp
client/join-test.cpp
client/keys-test.cpp
client/device-ops-test.cpp
client/room/room-actions-test.cpp
kazvjobtest.cpp
event-emitter-test.cpp
crypto-test.cpp
crypto/deterministic-test.cpp
promise-test.cpp
store-test.cpp
file-desc-test.cpp
)
target_include_directories(
kazvtest
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(kazvtest
PRIVATE Catch2::Catch2WithMain
PRIVATE kazv
PRIVATE kazveventemitter
PRIVATE kazvjob
PRIVATE nlohmann_json::nlohmann_json
PRIVATE immer
PRIVATE lager
PRIVATE zug)
+
+add_test(NAME kazvtest COMMAND kazvtest "~[needs-internet]")
diff --git a/src/tests/basejobtest.cpp b/src/tests/basejobtest.cpp
index d7a0389..da563dd 100644
--- a/src/tests/basejobtest.cpp
+++ b/src/tests/basejobtest.cpp
@@ -1,43 +1,43 @@
/*
* This file is part of libkazv.
* SPDX-FileCopyrightText: 2020 Tusooa Zhu
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <libkazv-config.hpp>
#include <catch2/catch_all.hpp>
#include <iostream>
#include <future>
#include <basejob.hpp>
#include <cprjobhandler.hpp>
#include "tests.hpp"
using namespace Kazv;
-TEST_CASE("Base job should fetch correctly", "[basejob]")
+TEST_CASE("Base job should fetch correctly", "[basejob][needs-internet]")
{
boost::asio::io_context ioContext;
BaseJob job(TEST_SERVER_URL, "/.well-known/matrix/client", BaseJob::Get{}, "TestJob");
CprJobHandler h(ioContext.get_executor());
h.submit(
job.withData(json{{"test", "bar"}}),
[&h](auto r) {
if (r.statusCode == 200) {
REQUIRE( isBodyJson(r.body) );
json j = r.jsonBody().get();
REQUIRE_NOTHROW( (j["m.homeserver"]["base_url"]) );
REQUIRE( (j["m.homeserver"]["base_url"].size() > 0) );
REQUIRE( r.dataStr("test") == "bar" );
}
h.stop();
});
ioContext.run();
}
diff --git a/src/tests/kazvjobtest.cpp b/src/tests/kazvjobtest.cpp
index 80bc15b..62f4076 100644
--- a/src/tests/kazvjobtest.cpp
+++ b/src/tests/kazvjobtest.cpp
@@ -1,243 +1,243 @@
/*
* This file is part of libkazv.
* SPDX-FileCopyrightText: 2020-2021 Tusooa Zhu <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <libkazv-config.hpp>
#include <vector>
#include <iostream>
#include <filesystem>
#include <catch2/catch_all.hpp>
#include <cprjobhandler.hpp>
#include "tests.hpp"
#include "kazvtest-respath.hpp"
#include "file-guard.hpp"
using namespace Kazv;
TEST_CASE("setTimeout should behave properly", "[kazvjob]")
{
boost::asio::io_context ioContext;
CprJobHandler h(ioContext.get_executor());
std::vector<int> v;
h.setTimeout(
[&v, &h] {
v.push_back(500);
h.stop();
}, 500);
h.setTimeout(
[&v] {
v.push_back(100);
}, 100);
ioContext.run();
REQUIRE( v.size() == 2 );
REQUIRE( v[0] == 100 );
REQUIRE( v[1] == 500 );
}
TEST_CASE("setInterval should behave properly", "[kazvjob]")
{
boost::asio::io_context ioContext;
CprJobHandler h(ioContext.get_executor());
std::vector<int> v;
h.setInterval(
[&v, &h] {
v.push_back(50);
std::cout << "timer executed" << std::endl;
if (v.size() >= 2) {
h.stop();
}
}, 100);
ioContext.run();
REQUIRE( v.size() == 2 );
REQUIRE( v[0] == 50 );
REQUIRE( v[1] == 50 );
}
TEST_CASE("setInterval can be cancelled", "[kazvjob]")
{
boost::asio::io_context ioContext;
CprJobHandler h(ioContext.get_executor());
std::vector<int> v;
std::string id{"testTimerId"};
h.setInterval(
[&v, &h, id] {
v.push_back(50);
std::cout << "timer executed" << std::endl;
if (v.size() >= 2) {
h.cancel(id);
}
}, 100, id);
h.setTimeout(
[&h] {
h.stop();
}, 300);
ioContext.run();
REQUIRE( v.size() == 2 );
REQUIRE( v[0] == 50 );
REQUIRE( v[1] == 50 );
}
static BaseJob succJob =
BaseJob(TEST_SERVER_URL, "/.well-known/matrix/client", BaseJob::Get{}, "TestJob")
.withQueue("testjob");
static BaseJob failJob =
BaseJob(TEST_SERVER_URL, "/.well-known/jfasjewfn/awejioaewjgjaad/fawre", BaseJob::Get{}, "AnotherTestJob")
.withQueue("testjob");
static BaseJob failJobWithCancel =
failJob.withQueue("testjob", CancelFutureIfFailed);
-TEST_CASE("Job queue should behave properly", "[kazvjob]")
+TEST_CASE("Job queue should behave properly", "[kazvjob][needs-internet]")
{
std::vector<bool> v;
std::function<void(Response)> callback =
[&v](Response r) {
std::cout << "callback called" << std::endl;
v.push_back(r.success());
};
boost::asio::io_context ioContext;
CprJobHandler h(ioContext.get_executor());
h.submit(succJob, callback); // true
h.submit(failJob, callback); // false
h.submit(failJobWithCancel, callback); // false
h.submit(succJob, callback); // false (because this is cancelled)
h.submit(succJob, [&h](Response) {
h.stop();
}); // nothing added
ioContext.run();
REQUIRE( v.size() == 4 );
REQUIRE( v[0] == true );
REQUIRE( v[1] == false );
REQUIRE( v[2] == false );
REQUIRE( v[3] == false );
}
static const std::string httpbinServer = "http://www.httpbin.org";
static const std::string httpbinEndpoint = "/post";
-TEST_CASE("Stream uploads should work properly", "[kazvjob]")
+TEST_CASE("Stream uploads should work properly", "[kazvjob][needs-internet]")
{
auto filename = std::filesystem::path(resPath) / "kazvjob-test-res1";
auto desc = FileDesc(filename.native(), "text/plain");
BaseJob job(httpbinServer,
httpbinEndpoint,
BaseJob::POST,
"TestJob",
std::string{}, // token
BaseJob::ReturnType::Json,
desc);
boost::asio::io_context ioContext;
CprJobHandler h(ioContext.get_executor());
h.submit(job, [&h](Response r) {
REQUIRE(isBodyJson(r.body));
auto body = r.jsonBody();
std::cout << "Ret= " << body.get().dump() << std::endl;
REQUIRE(body.get().at("data").template get<std::string>() == "foobar");
REQUIRE(body.get().at("headers").at("Content-Type").template get<std::string>() == "text/plain");
h.stop();
});
ioContext.run();
}
-TEST_CASE("Streaming binary data should be ok", "[kazvjob]")
+TEST_CASE("Streaming binary data should be ok", "[kazvjob][needs-internet]")
{
auto filename = std::filesystem::path(resPath) / "kazvjob-test-res2";
auto desc = FileDesc(filename.native(), "application/octet-stream");
BaseJob job(httpbinServer,
httpbinEndpoint,
BaseJob::POST,
"TestJob",
std::string{}, // token
BaseJob::ReturnType::Json,
desc);
boost::asio::io_context ioContext;
CprJobHandler h(ioContext.get_executor());
h.submit(job, [&h](Response r) {
REQUIRE(isBodyJson(r.body));
auto body = r.jsonBody();
std::cout << "Ret= " << body.get().dump() << std::endl;
REQUIRE(body.get().at("data").template get<std::string>() == "\n\r\n\0\t\n"s);
REQUIRE(body.get().at("headers").at("Content-Type").template get<std::string>() == "application/octet-stream");
h.stop();
});
ioContext.run();
}
-TEST_CASE("Stream downloads should work properly", "[kazvjob]")
+TEST_CASE("Stream downloads should work properly", "[kazvjob][needs-internet]")
{
auto filename = std::filesystem::path(resPath) / "kazvjob-test-tmp1";
auto desc = FileDesc(filename.native());
auto guard = FileGuard{filename};
BaseJob job(httpbinServer,
httpbinEndpoint,
BaseJob::POST,
"TestJob",
std::string{}, // token
BaseJob::ReturnType::File,
"foobar"s,
{}, // query
Header(Header::value_type{{"Content-Type", "text/plain"}}), // header
desc);
boost::asio::io_context ioContext;
CprJobHandler h(ioContext.get_executor());
h.submit(job, [&h, filename](Response r) {
REQUIRE(std::holds_alternative<FileDesc>(r.body));
auto body = std::get<FileDesc>(r.body);
REQUIRE(body.name().has_value());
REQUIRE(body.name().value() == filename);
auto fh = DumbFileInterface{};
auto stream = body.provider(fh).getStream();
stream.read(1024, [](auto retCode, auto data) {
REQUIRE(retCode == FileOpRetCode::Success);
auto j = json::parse(data.begin(), data.end());
std::cout << j.dump() << std::endl;
REQUIRE(j.at("data") == "foobar");
REQUIRE(j.at("headers").at("Content-Type") == "text/plain");
});
h.stop();
});
ioContext.run();
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 3:29 PM (20 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55269
Default Alt Text
(17 KB)
Attached To
Mode
rL libkazv
Attached
Detach File
Event Timeline
Log In to Comment