comparison tests/cmd-plugin-list/main.cpp @ 317:249ccc1e4840

Tests: add test for plugin-list, #559
author David Demelier <markand@malikania.fr>
date Sun, 23 Oct 2016 11:20:29 +0200
parents
children a6c3d73d9641
comparison
equal deleted inserted replaced
316:ee2593e7e670 317:249ccc1e4840
1 /*
2 * main.cpp -- test plugin-list remote command
3 *
4 * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <cmd-plugin-list.hpp>
20 #include <command-tester.hpp>
21 #include <server-tester.hpp>
22 #include <service-plugin.hpp>
23 #include <plugin.hpp>
24
25 using namespace irccd;
26 using namespace irccd::command;
27
28 namespace {
29
30 class PluginListCommandTest : public CommandTester {
31 public:
32 PluginListCommandTest()
33 : CommandTester(std::make_unique<PluginListCommand>())
34 {
35 m_irccd.plugins().add(std::make_unique<Plugin>("t1", ""));
36 m_irccd.plugins().add(std::make_unique<Plugin>("t2", ""));
37 }
38 };
39
40 TEST_F(PluginListCommandTest, basic)
41 {
42 try {
43 auto response = nlohmann::json();
44
45 m_irccdctl.client().onMessage.connect([&] (auto message) {
46 response = message;
47 });
48 m_irccdctl.client().request({{ "command", "plugin-list" }});
49
50 poll([&] () {
51 return response.is_object();
52 });
53
54 ASSERT_TRUE(response.is_object());
55 ASSERT_EQ("t1", response["list"][0]);
56 ASSERT_EQ("t2", response["list"][1]);
57 } catch (const std::exception &ex) {
58 FAIL() << ex.what();
59 }
60 }
61
62 } // !namespace
63
64 int main(int argc, char **argv)
65 {
66 testing::InitGoogleTest(&argc, argv);
67
68 return RUN_ALL_TESTS();
69 }