changeset 738:199f36d4edc8

Tests: add mock_plugin class, closes #898
author David Demelier <markand@malikania.fr>
date Wed, 25 Jul 2018 12:33:11 +0200
parents 190b16cfa848
children 46a1877749ff
files libirccd-test/CMakeLists.txt libirccd-test/irccd/test/mock.cpp libirccd-test/irccd/test/mock.hpp libirccd-test/irccd/test/mock_plugin.cpp libirccd-test/irccd/test/mock_plugin.hpp tests/src/irccdctl/cli-plugin-config/main.cpp tests/src/irccdctl/cli-plugin-info/main.cpp tests/src/irccdctl/cli-plugin-list/main.cpp tests/src/irccdctl/cli-plugin-load/main.cpp tests/src/libirccd/command-plugin-config/main.cpp tests/src/libirccd/command-plugin-info/main.cpp tests/src/libirccd/command-plugin-list/main.cpp tests/src/libirccd/command-plugin-load/main.cpp tests/src/libirccd/command-plugin-reload/main.cpp tests/src/libirccd/command-plugin-unload/main.cpp
diffstat 15 files changed, 436 insertions(+), 236 deletions(-) [+]
line wrap: on
line diff
--- a/libirccd-test/CMakeLists.txt	Tue Jul 24 23:01:00 2018 +0200
+++ b/libirccd-test/CMakeLists.txt	Wed Jul 25 12:33:11 2018 +0200
@@ -24,6 +24,7 @@
     ${libirccd-test_SOURCE_DIR}/irccd/test/command_test.hpp
     ${libirccd-test_SOURCE_DIR}/irccd/test/debug_server.hpp
     ${libirccd-test_SOURCE_DIR}/irccd/test/mock.hpp
+    ${libirccd-test_SOURCE_DIR}/irccd/test/mock_plugin.hpp
     ${libirccd-test_SOURCE_DIR}/irccd/test/mock_server.hpp
     ${libirccd-test_SOURCE_DIR}/irccd/test/plugin_cli_test.hpp
     ${libirccd-test_SOURCE_DIR}/irccd/test/rule_cli_test.hpp
@@ -36,6 +37,7 @@
     ${libirccd-test_SOURCE_DIR}/irccd/test/cli_test.cpp
     ${libirccd-test_SOURCE_DIR}/irccd/test/debug_server.cpp
     ${libirccd-test_SOURCE_DIR}/irccd/test/mock.cpp
+    ${libirccd-test_SOURCE_DIR}/irccd/test/mock_plugin.cpp
     ${libirccd-test_SOURCE_DIR}/irccd/test/mock_server.cpp
     ${libirccd-test_SOURCE_DIR}/irccd/test/plugin_cli_test.cpp
     ${libirccd-test_SOURCE_DIR}/irccd/test/rule_cli_test.cpp
--- a/libirccd-test/irccd/test/mock.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/libirccd-test/irccd/test/mock.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -20,12 +20,12 @@
 
 namespace irccd {
 
-void mock::push(std::string name, args args)
+void mock::push(std::string name, args args) const
 {
     table_[name].push_back(std::move(args));
 }
 
-auto mock::find(const std::string& name) -> std::vector<args>
+auto mock::find(const std::string& name) const -> std::vector<args>
 {
     if (const auto it = table_.find(name); it != table_.end())
         return it->second;
@@ -33,12 +33,12 @@
     return {};
 }
 
-void mock::clear(const std::string& name) noexcept
+void mock::clear(const std::string& name) const noexcept
 {
     table_.erase(name);
 }
 
-void mock::clear() noexcept
+void mock::clear() const noexcept
 {
     table_.clear();
 }
--- a/libirccd-test/irccd/test/mock.hpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/libirccd-test/irccd/test/mock.hpp	Wed Jul 25 12:33:11 2018 +0200
@@ -48,7 +48,7 @@
     using functions = std::unordered_map<std::string, std::vector<args>>;
 
 private:
-    functions table_;
+    mutable functions table_;
 
 public:
     /**
@@ -57,7 +57,7 @@
      * \param name the function name
      * \param args the arguments list
      */
-    void push(std::string name, args args = {});
+    void push(std::string name, args args = {}) const;
 
     /**
      * Get all function invocations by name.
@@ -65,19 +65,19 @@
      * \param name the function name
      * \return the list of functions and their arguments or empty if not called
      */
-    auto find(const std::string& name) -> std::vector<args>;
+    auto find(const std::string& name) const -> std::vector<args>;
 
     /**
      * Clear all function invocations by name.
      *
      * \param name the function name
      */
-    void clear(const std::string& name) noexcept;
+    void clear(const std::string& name) const noexcept;
 
     /**
      * Clear all function invocations.
      */
-    void clear() noexcept;
+    void clear() const noexcept;
 
     /**
      * Tells if no functions have been called.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libirccd-test/irccd/test/mock_plugin.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -0,0 +1,192 @@
+/*
+ * mock_plugin.cpp -- mock plugin
+ *
+ * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <irccd/daemon/server.hpp>
+
+#include "mock_plugin.hpp"
+
+namespace irccd {
+
+auto mock_plugin::get_name() const noexcept -> std::string_view
+{
+    push("get_name");
+
+    return "mock";
+}
+
+auto mock_plugin::get_author() const noexcept -> std::string_view
+{
+    push("get_author");
+
+    return "David Demelier <markand@malikania.fr>";
+}
+
+auto mock_plugin::get_license() const noexcept -> std::string_view
+{
+    push("get_license");
+
+    return "ISC";
+}
+
+auto mock_plugin::get_summary() const noexcept -> std::string_view
+{
+    push("get_summary");
+
+    return "mock plugin";
+}
+
+auto mock_plugin::get_version() const noexcept -> std::string_view
+{
+    push("get_version");
+
+    return "1.0";
+}
+
+auto mock_plugin::get_options() const -> map
+{
+    push("get_options");
+
+    return options_;
+}
+
+void mock_plugin::set_options(const map& map)
+{
+    push("set_options", { map });
+
+    options_ = map;
+}
+
+auto mock_plugin::get_formats() const -> map
+{
+    push("get_formats");
+
+    return formats_;
+}
+
+void mock_plugin::set_formats(const map& map)
+{
+    push("set_formats", { map });
+
+    formats_ = map;
+}
+
+auto mock_plugin::get_paths() const -> map
+{
+    push("get_paths");
+
+    return paths_;
+}
+
+void mock_plugin::set_paths(const map& map)
+{
+    push("set_paths", { map });
+
+    paths_ = map;
+}
+
+void mock_plugin::handle_command(irccd&, const message_event& event)
+{
+    push("handle_command", { event });
+}
+
+void mock_plugin::handle_connect(irccd&, const connect_event& event)
+{
+    push("handle_connect", { event });
+}
+
+void mock_plugin::handle_disconnect(irccd&, const disconnect_event& event)
+{
+    push("handle_disconnect", { event });
+}
+
+void mock_plugin::handle_invite(irccd&, const invite_event& event)
+{
+    push("handle_invite", { event });
+}
+
+void mock_plugin::handle_join(irccd&, const join_event& event)
+{
+    push("handle_join", { event });
+}
+
+void mock_plugin::handle_kick(irccd&, const kick_event& event)
+{
+    push("handle_kick", { event });
+}
+
+void mock_plugin::handle_load(irccd&)
+{
+    push("handle_load");
+}
+
+void mock_plugin::handle_message(irccd&, const message_event& event)
+{
+    push("handle_message", { event });
+}
+
+void mock_plugin::handle_me(irccd&, const me_event& event)
+{
+    push("handle_me", { event });
+}
+
+void mock_plugin::handle_mode(irccd&, const mode_event& event)
+{
+    push("handle_mode", { event });
+}
+
+void mock_plugin::handle_names(irccd&, const names_event& event)
+{
+    push("handle_names", { event });
+}
+
+void mock_plugin::handle_nick(irccd&, const nick_event& event)
+{
+    push("handle_nick", { event });
+}
+
+void mock_plugin::handle_notice(irccd&, const notice_event& event)
+{
+    push("handle_notice", { event });
+}
+
+void mock_plugin::handle_part(irccd&, const part_event& event)
+{
+    push("handle_part", { event });
+}
+
+void mock_plugin::handle_reload(irccd&)
+{
+    push("handle_reload");
+}
+
+void mock_plugin::handle_topic(irccd&, const topic_event& event)
+{
+    push("handle_topic", { event });
+}
+
+void mock_plugin::handle_unload(irccd&)
+{
+    push("handle_unload");
+}
+
+void mock_plugin::handle_whois(irccd&, const whois_event& event)
+{
+    push("handle_whois", { event });
+}
+
+} // !irccd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libirccd-test/irccd/test/mock_plugin.hpp	Wed Jul 25 12:33:11 2018 +0200
@@ -0,0 +1,193 @@
+/*
+ * mock_plugin.hpp -- mock plugin
+ *
+ * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef IRCCD_TEST_MOCK_PLUGIN_HPP
+#define IRCCD_TEST_MOCK_PLUGIN_HPP
+
+/**
+ * \file mock_plugin.hpp
+ * \brief Mock plugin.
+ */
+
+#include <irccd/daemon/plugin.hpp>
+
+#include "mock.hpp"
+
+namespace irccd {
+
+/**
+ * \brief Mock plugin.
+ */
+class mock_plugin : public plugin, public mock {
+private:
+    map options_;
+    map formats_;
+    map paths_;
+
+public:
+    using plugin::plugin;
+
+    /**
+     * \copydoc plugin::get_name
+     */
+    auto get_name() const noexcept -> std::string_view override;
+
+    /**
+     * \copydoc plugin::get_author
+     */
+    auto get_author() const noexcept -> std::string_view override;
+
+    /**
+     * \copydoc plugin::get_license
+     */
+    auto get_license() const noexcept -> std::string_view override;
+
+    /**
+     * \copydoc plugin::get_summary
+     */
+    auto get_summary() const noexcept -> std::string_view override;
+
+    /**
+     * \copydoc plugin::get_version
+     */
+    auto get_version() const noexcept -> std::string_view override;
+
+    /**
+     * \copydoc plugin::get_options
+     */
+    auto get_options() const -> map override;
+
+    /**
+     * \copydoc plugin::set_options
+     */
+    void set_options(const map& map) override;
+
+    /**
+     * \copydoc plugin::get_formats
+     */
+    auto get_formats() const -> map override;
+
+    /**
+     * \copydoc plugin::set_formats
+     */
+    void set_formats(const map& map) override;
+
+    /**
+     * \copydoc plugin::get_paths
+     */
+    auto get_paths() const -> map override;
+
+    /**
+     * \copydoc plugin::set_path
+     */
+    void set_paths(const map& map) override;
+
+    /**
+     * \copydoc plugin::handle_command
+     */
+    void handle_command(irccd& irccd, const message_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_connect
+     */
+    void handle_connect(irccd& irccd, const connect_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_disconnect
+     */
+    void handle_disconnect(irccd& irccd, const disconnect_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_invite
+     */
+    void handle_invite(irccd& irccd, const invite_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_join
+     */
+    void handle_join(irccd& irccd, const join_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_kick
+     */
+    void handle_kick(irccd& irccd, const kick_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_load
+     */
+    void handle_load(irccd& irccd) override;
+
+    /**
+     * \copydoc plugin::handle_message
+     */
+    void handle_message(irccd& irccd, const message_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_me
+     */
+    void handle_me(irccd& irccd, const me_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_mode
+     */
+    void handle_mode(irccd& irccd, const mode_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_names
+     */
+    void handle_names(irccd& irccd, const names_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_nick
+     */
+    void handle_nick(irccd& irccd, const nick_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_notice
+     */
+    void handle_notice(irccd& irccd, const notice_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_part
+     */
+    void handle_part(irccd& irccd, const part_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_reload
+     */
+    void handle_reload(irccd& irccd) override;
+
+    /**
+     * \copydoc plugin::handle_topic
+     */
+    void handle_topic(irccd& irccd, const topic_event& event) override;
+
+    /**
+     * \copydoc plugin::handle_unload
+     */
+    void handle_unload(irccd& irccd) override;
+
+    /**
+     * \copydoc plugin::handle_whois
+     */
+    void handle_whois(irccd& irccd, const whois_event& event) override;
+};
+
+} // !irccd
+
+#endif // !IRCCD_TEST_MOCK_PLUGIN_HPP
--- a/tests/src/irccdctl/cli-plugin-config/main.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/tests/src/irccdctl/cli-plugin-config/main.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -20,40 +20,18 @@
 #include <boost/test/unit_test.hpp>
 
 #include <irccd/test/plugin_cli_test.hpp>
+#include <irccd/test/mock_plugin.hpp>
 
 namespace irccd {
 
 namespace {
 
-class configurable_plugin : public plugin {
-private:
-    map config_;
-
-public:
-    using plugin::plugin;
-
-    auto get_name() const noexcept -> std::string_view override
-    {
-        return "config";
-    }
-
-    auto get_options() const -> map override
-    {
-        return config_;
-    }
-
-    void set_options(const map& config) override
-    {
-        config_ = std::move(config);
-    }
-};
-
 class configurable_plugin_cli_test : public plugin_cli_test {
 public:
     configurable_plugin_cli_test()
     {
-        auto conf1 = std::make_unique<configurable_plugin>("conf1");
-        auto conf2 = std::make_unique<configurable_plugin>("conf2");
+        auto conf1 = std::make_unique<mock_plugin>("conf1");
+        auto conf2 = std::make_unique<mock_plugin>("conf2");
 
         conf1->set_options({
             { "v1", "123" },
--- a/tests/src/irccdctl/cli-plugin-info/main.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/tests/src/irccdctl/cli-plugin-info/main.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -20,51 +20,17 @@
 #include <boost/test/unit_test.hpp>
 
 #include <irccd/test/plugin_cli_test.hpp>
+#include <irccd/test/mock_plugin.hpp>
 
 namespace irccd {
 
 namespace {
 
-class sample : public plugin {
-public:
-    sample()
-        : plugin("test")
-    {
-    }
-
-    auto get_name() const noexcept -> std::string_view override
-    {
-        return "sample";
-    }
-
-    auto get_author() const noexcept -> std::string_view override
-    {
-        return "David Demelier <markand@malikania.fr>";
-    }
-
-    auto get_license() const noexcept -> std::string_view override
-    {
-        return "ISC";
-    }
-
-    auto get_summary() const noexcept -> std::string_view override
-    {
-        return "foo";
-    }
-
-    auto get_version() const noexcept -> std::string_view override
-    {
-        return "0.0";
-    }
-};
-
 BOOST_FIXTURE_TEST_SUITE(plugin_info_suite, plugin_cli_test)
 
 BOOST_AUTO_TEST_CASE(simple)
 {
-    auto p = std::make_unique<sample>();
-
-    irccd_.plugins().add(std::move(p));
+    irccd_.plugins().add(std::make_unique<mock_plugin>("test"));
     start();
 
     const auto [out, err] = exec({ "plugin-info", "test" });
@@ -73,8 +39,8 @@
     BOOST_TEST(err.size() == 0U);
     BOOST_TEST(out[0] == "Author         : David Demelier <markand@malikania.fr>");
     BOOST_TEST(out[1] == "License        : ISC");
-    BOOST_TEST(out[2] == "Summary        : foo");
-    BOOST_TEST(out[3] == "Version        : 0.0");
+    BOOST_TEST(out[2] == "Summary        : mock plugin");
+    BOOST_TEST(out[3] == "Version        : 1.0");
 }
 
 BOOST_AUTO_TEST_SUITE_END()
--- a/tests/src/irccdctl/cli-plugin-list/main.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/tests/src/irccdctl/cli-plugin-list/main.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -20,30 +20,18 @@
 #include <boost/test/unit_test.hpp>
 
 #include <irccd/test/plugin_cli_test.hpp>
+#include <irccd/test/mock_plugin.hpp>
 
 namespace irccd {
 
 namespace {
 
-class sample : public plugin {
-public:
-    sample(std::string id)
-        : plugin(std::move(id))
-    {
-    }
-
-    auto get_name() const noexcept -> std::string_view override
-    {
-        return "sample";
-    }
-};
-
 BOOST_FIXTURE_TEST_SUITE(plugin_list_suite, plugin_cli_test)
 
 BOOST_AUTO_TEST_CASE(output)
 {
-    irccd_.plugins().add(std::make_unique<sample>("p1"));
-    irccd_.plugins().add(std::make_unique<sample>("p2"));
+    irccd_.plugins().add(std::make_unique<mock_plugin>("p1"));
+    irccd_.plugins().add(std::make_unique<mock_plugin>("p2"));
     start();
 
     const auto [out, err] = exec({ "plugin-list" });
--- a/tests/src/irccdctl/cli-plugin-load/main.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/tests/src/irccdctl/cli-plugin-load/main.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -20,21 +20,12 @@
 #include <boost/test/unit_test.hpp>
 
 #include <irccd/test/plugin_cli_test.hpp>
+#include <irccd/test/mock_plugin.hpp>
 
 namespace irccd {
 
 namespace {
 
-class sample : public plugin {
-public:
-    using plugin::plugin;
-
-    auto get_name() const noexcept -> std::string_view override
-    {
-        return "sample";
-    }
-};
-
 class custom_plugin_loader : public plugin_loader {
 public:
     custom_plugin_loader()
@@ -44,12 +35,12 @@
 
     auto find(std::string_view id) -> std::shared_ptr<plugin> override
     {
-        return std::make_unique<sample>(std::string(id));
+        return std::make_unique<mock_plugin>(std::string(id));
     }
 
     auto open(std::string_view id, std::string_view) -> std::shared_ptr<plugin> override
     {
-        return std::make_unique<sample>(std::string(id));
+        return std::make_unique<mock_plugin>(std::string(id));
     }
 };
 
@@ -59,14 +50,14 @@
 
 BOOST_AUTO_TEST_CASE(simple)
 {
-    irccd_.plugins().add(std::make_unique<sample>("p1"));
-    irccd_.plugins().add(std::make_unique<sample>("p2"));
+    irccd_.plugins().add(std::make_unique<mock_plugin>("p1"));
+    irccd_.plugins().add(std::make_unique<mock_plugin>("p2"));
     irccd_.plugins().add_loader(std::make_unique<custom_plugin_loader>());
     start();
 
     // Load a plugin first.
     {
-        const auto [out, err] = exec({ "plugin-load", "sample" });
+        const auto [out, err] = exec({ "plugin-load", "test" });
 
         BOOST_TEST(out.size() == 0U);
         BOOST_TEST(err.size() == 0U);
@@ -80,7 +71,7 @@
         BOOST_TEST(err.size() == 0U);
         BOOST_TEST(out[0] == "p1");
         BOOST_TEST(out[1] == "p2");
-        BOOST_TEST(out[2] == "sample");
+        BOOST_TEST(out[2] == "test");
     }
 }
 
--- a/tests/src/libirccd/command-plugin-config/main.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/tests/src/libirccd/command-plugin-config/main.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -23,41 +23,17 @@
 #include <irccd/daemon/service/plugin_service.hpp>
 
 #include <irccd/test/command_test.hpp>
+#include <irccd/test/mock_plugin.hpp>
 
 namespace irccd {
 
 namespace {
 
-class custom_plugin : public plugin {
-public:
-    map config_;
-
-    custom_plugin()
-        : plugin("test")
-    {
-    }
-
-    auto get_name() const noexcept -> std::string_view override
-    {
-        return "test";
-    }
-
-    auto get_options() const -> map override
-    {
-        return config_;
-    }
-
-    void set_options(const map& options) override
-    {
-        config_ = std::move(options);
-    }
-};
-
 BOOST_FIXTURE_TEST_SUITE(plugin_config_test_suite, command_test<plugin_config_command>)
 
 BOOST_AUTO_TEST_CASE(set)
 {
-    daemon_->plugins().add(std::make_unique<custom_plugin>());
+    daemon_->plugins().add(std::make_unique<mock_plugin>("test"));
 
     const auto [json, code] = request({
         { "command",    "plugin-config" },
@@ -75,7 +51,7 @@
 
 BOOST_AUTO_TEST_CASE(get)
 {
-    auto plugin = std::make_unique<custom_plugin>();
+    auto plugin = std::make_unique<mock_plugin>("test");
 
     plugin->set_options({
         { "x1", "10" },
@@ -96,7 +72,7 @@
 
 BOOST_AUTO_TEST_CASE(getall)
 {
-    auto plugin = std::make_unique<custom_plugin>();
+    auto plugin = std::make_unique<mock_plugin>("test");
 
     plugin->set_options({
         { "x1", "10" },
--- a/tests/src/libirccd/command-plugin-info/main.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/tests/src/libirccd/command-plugin-info/main.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -23,49 +23,17 @@
 #include <irccd/daemon/service/plugin_service.hpp>
 
 #include <irccd/test/command_test.hpp>
+#include <irccd/test/mock_plugin.hpp>
 
 namespace irccd {
 
 namespace {
 
-class sample_plugin : public plugin {
-public:
-    sample_plugin()
-        : plugin("test")
-    {
-    }
-
-    auto get_name() const noexcept -> std::string_view override
-    {
-        return "test";
-    }
-
-    auto get_author() const noexcept -> std::string_view override
-    {
-        return "Francis Beaugrand";
-    }
-
-    auto get_license() const noexcept -> std::string_view override
-    {
-        return "GPL";
-    }
-
-    auto get_summary() const noexcept -> std::string_view override
-    {
-        return "Completely useless plugin";
-    }
-
-    auto get_version() const noexcept -> std::string_view override
-    {
-        return "0.0.0.0.0.0.0.0.1-beta5";
-    }
-};
-
 BOOST_FIXTURE_TEST_SUITE(plugin_info_test_suite, command_test<plugin_info_command>)
 
 BOOST_AUTO_TEST_CASE(basic)
 {
-    daemon_->plugins().add(std::make_unique<sample_plugin>());
+    daemon_->plugins().add(std::make_unique<mock_plugin>("test"));
 
     const auto [json, code] = request({
         { "command",    "plugin-info"       },
@@ -73,10 +41,10 @@
     });
 
     BOOST_TEST(!code);
-    BOOST_TEST(json["author"].get<std::string>() == "Francis Beaugrand");
-    BOOST_TEST(json["license"].get<std::string>() == "GPL");
-    BOOST_TEST(json["summary"].get<std::string>() == "Completely useless plugin");
-    BOOST_TEST(json["version"].get<std::string>() == "0.0.0.0.0.0.0.0.1-beta5");
+    BOOST_TEST(json["author"].get<std::string>() == "David Demelier <markand@malikania.fr>");
+    BOOST_TEST(json["license"].get<std::string>() == "ISC");
+    BOOST_TEST(json["summary"].get<std::string>() == "mock plugin");
+    BOOST_TEST(json["version"].get<std::string>() == "1.0");
 }
 
 BOOST_AUTO_TEST_SUITE(errors)
--- a/tests/src/libirccd/command-plugin-list/main.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/tests/src/libirccd/command-plugin-list/main.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -23,27 +23,18 @@
 #include <irccd/daemon/service/plugin_service.hpp>
 
 #include <irccd/test/command_test.hpp>
+#include <irccd/test/mock_plugin.hpp>
 
 namespace irccd {
 
 namespace {
 
-class sample_plugin : public plugin {
-public:
-    using plugin::plugin;
-
-    auto get_name() const noexcept -> std::string_view override
-    {
-        return "sample";
-    }
-};
-
 class plugin_list_test : public command_test<plugin_list_command> {
 public:
     plugin_list_test()
     {
-        daemon_->plugins().add(std::make_unique<sample_plugin>("t1"));
-        daemon_->plugins().add(std::make_unique<sample_plugin>("t2"));
+        daemon_->plugins().add(std::make_unique<mock_plugin>("t1"));
+        daemon_->plugins().add(std::make_unique<mock_plugin>("t2"));
     }
 };
 
--- a/tests/src/libirccd/command-plugin-load/main.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/tests/src/libirccd/command-plugin-load/main.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -23,6 +23,7 @@
 #include <irccd/daemon/service/plugin_service.hpp>
 
 #include <irccd/test/command_test.hpp>
+#include <irccd/test/mock_plugin.hpp>
 
 namespace irccd {
 
@@ -67,20 +68,10 @@
     }
 };
 
-class sample : public plugin {
-public:
-    using plugin::plugin;
-
-    auto get_name() const noexcept -> std::string_view override
-    {
-        return "test";
-    }
-};
-
 class sample_loader : public plugin_loader {
 public:
     sample_loader()
-        : plugin_loader({}, {".none"})
+        : plugin_loader({}, { ".none" })
     {
     }
 
@@ -92,7 +83,7 @@
     auto find(std::string_view id) noexcept -> std::shared_ptr<plugin> override
     {
         if (id == "test")
-            return std::make_unique<sample>("test");
+            return std::make_unique<mock_plugin>("test");
 
         return nullptr;
     }
@@ -104,7 +95,7 @@
     {
         daemon_->plugins().add_loader(std::make_unique<sample_loader>());
         daemon_->plugins().add_loader(std::make_unique<broken_loader>());
-        daemon_->plugins().add(std::make_unique<sample>("already"));
+        daemon_->plugins().add(std::make_unique<mock_plugin>("already"));
     }
 };
 
--- a/tests/src/libirccd/command-plugin-reload/main.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/tests/src/libirccd/command-plugin-reload/main.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -23,30 +23,12 @@
 #include <irccd/daemon/service/plugin_service.hpp>
 
 #include <irccd/test/command_test.hpp>
-#include <irccd/test/mock.hpp>
+#include <irccd/test/mock_plugin.hpp>
 
 namespace irccd {
 
 namespace {
 
-class reloadable_plugin : public mock, public plugin {
-public:
-    reloadable_plugin()
-        : plugin("test")
-    {
-    }
-
-    auto get_name() const noexcept -> std::string_view override
-    {
-        return "reload";
-    }
-
-    void handle_reload(irccd&) override
-    {
-        push("handle_reload");
-    }
-};
-
 class broken_plugin : public plugin {
 public:
     broken_plugin()
@@ -67,10 +49,10 @@
 
 class plugin_reload_test : public command_test<plugin_reload_command> {
 protected:
-    std::shared_ptr<reloadable_plugin> plugin_;
+    std::shared_ptr<mock_plugin> plugin_;
 
     plugin_reload_test()
-        : plugin_(std::make_shared<reloadable_plugin>())
+        : plugin_(std::make_shared<mock_plugin>("test"))
     {
         daemon_->plugins().add(plugin_);
         daemon_->plugins().add(std::make_unique<broken_plugin>());
--- a/tests/src/libirccd/command-plugin-unload/main.cpp	Tue Jul 24 23:01:00 2018 +0200
+++ b/tests/src/libirccd/command-plugin-unload/main.cpp	Wed Jul 25 12:33:11 2018 +0200
@@ -23,30 +23,12 @@
 #include <irccd/daemon/service/plugin_service.hpp>
 
 #include <irccd/test/command_test.hpp>
-#include <irccd/test/mock.hpp>
+#include <irccd/test/mock_plugin.hpp>
 
 namespace irccd {
 
 namespace {
 
-class unloadable_plugin : public mock, public plugin {
-public:
-    unloadable_plugin()
-        : plugin("test")
-    {
-    }
-
-    auto get_name() const noexcept -> std::string_view override
-    {
-        return "unload";
-    }
-
-    void handle_unload(irccd&) override
-    {
-        push("handle_unload");
-    }
-};
-
 class broken_plugin : public plugin {
 public:
     broken_plugin()
@@ -67,10 +49,10 @@
 
 class plugin_unload_test : public command_test<plugin_unload_command> {
 protected:
-    std::shared_ptr<unloadable_plugin> plugin_;
+    std::shared_ptr<mock_plugin> plugin_;
 
     plugin_unload_test()
-        : plugin_(std::make_shared<unloadable_plugin>())
+        : plugin_(std::make_shared<mock_plugin>("test"))
     {
         daemon_->plugins().add(plugin_);
         daemon_->plugins().add(std::make_unique<broken_plugin>());