annotate tests/src/libirccd/command-server-disconnect/main.cpp @ 760:35c1517d705d

Tests: make consistency
author David Demelier <markand@malikania.fr>
date Fri, 10 Aug 2018 12:29:00 +0200
parents 97b356010785
children 8c44bbcbbab9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
1 /*
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
2 * main.cpp -- test server-disconnect remote command
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
3 *
628
27587ff92a64 Misc: update copyrights
David Demelier <markand@malikania.fr>
parents: 624
diff changeset
4 * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
5 *
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
6 * Permission to use, copy, modify, and/or distribute this software for any
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
8 * copyright notice and this permission notice appear in all copies.
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
9 *
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
17 */
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
18
558
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
19 #define BOOST_TEST_MODULE "server-disconnect"
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
20 #include <boost/test/unit_test.hpp>
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
21
757
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
22 #include <irccd/test/command_fixture.hpp>
558
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
23
760
35c1517d705d Tests: make consistency
David Demelier <markand@malikania.fr>
parents: 757
diff changeset
24 using namespace irccd::test;
35c1517d705d Tests: make consistency
David Demelier <markand@malikania.fr>
parents: 757
diff changeset
25
35c1517d705d Tests: make consistency
David Demelier <markand@malikania.fr>
parents: 757
diff changeset
26 namespace irccd {
558
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
27
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
28 namespace {
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
29
757
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
30 class server_disconnect_fixture : public command_fixture {
558
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
31 protected:
735
64839725f346 Tests: replace journal_server with mock_server
David Demelier <markand@malikania.fr>
parents: 723
diff changeset
32 std::shared_ptr<mock_server> s1_;
64839725f346 Tests: replace journal_server with mock_server
David Demelier <markand@malikania.fr>
parents: 723
diff changeset
33 std::shared_ptr<mock_server> s2_;
64839725f346 Tests: replace journal_server with mock_server
David Demelier <markand@malikania.fr>
parents: 723
diff changeset
34
757
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
35 server_disconnect_fixture()
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
36 : s1_(new mock_server(ctx_, "s1", "localhost"))
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
37 , s2_(new mock_server(ctx_, "s2", "localhost"))
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
38 {
757
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
39 irccd_.servers().add(s1_);
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
40 irccd_.servers().add(s2_);
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
41 }
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
42 };
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
43
757
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
44 BOOST_FIXTURE_TEST_SUITE(server_disconnect_fixture_suite, server_disconnect_fixture)
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
45
558
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
46 BOOST_AUTO_TEST_CASE(one)
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
47 {
737
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
48 const auto [json, code] = request({
558
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
49 { "command", "server-disconnect" },
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
50 { "server", "s1" }
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
51 });
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
52
737
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
53 BOOST_TEST(!code);
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
54 BOOST_TEST(json["command"].get<std::string>() == "server-disconnect");
735
64839725f346 Tests: replace journal_server with mock_server
David Demelier <markand@malikania.fr>
parents: 723
diff changeset
55 BOOST_TEST(s1_->find("disconnect").size() == 1U);
757
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
56 BOOST_TEST(!irccd_.servers().has("s1"));
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
57 BOOST_TEST(irccd_.servers().has("s2"));
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
58 }
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
59
558
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
60 BOOST_AUTO_TEST_CASE(all)
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
61 {
737
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
62 const auto [json, code] = request({{ "command", "server-disconnect" }});
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
63
737
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
64 BOOST_TEST(!code);
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
65 BOOST_TEST(json["command"].get<std::string>() == "server-disconnect");
735
64839725f346 Tests: replace journal_server with mock_server
David Demelier <markand@malikania.fr>
parents: 723
diff changeset
66 BOOST_TEST(s1_->find("disconnect").size() == 1U);
64839725f346 Tests: replace journal_server with mock_server
David Demelier <markand@malikania.fr>
parents: 723
diff changeset
67 BOOST_TEST(s2_->find("disconnect").size() == 1U);
757
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
68 BOOST_TEST(!irccd_.servers().has("s1"));
97b356010785 Irccd: create (command|jsapi)::registry
David Demelier <markand@malikania.fr>
parents: 754
diff changeset
69 BOOST_TEST(!irccd_.servers().has("s2"));
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
70 }
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
71
578
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
72 BOOST_AUTO_TEST_SUITE(errors)
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
73
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
74 BOOST_AUTO_TEST_CASE(invalid_identifier)
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
75 {
737
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
76 const auto [json, code] = request({
578
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
77 { "command", "server-disconnect" },
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
78 { "server", 123456 }
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
79 });
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
80
737
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
81 BOOST_TEST(code == server_error::invalid_identifier);
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
82 BOOST_TEST(json["error"].get<int>() == server_error::invalid_identifier);
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
83 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
578
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
84 }
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
85
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
86 BOOST_AUTO_TEST_CASE(not_found)
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
87 {
737
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
88 const auto [json, code] = request({
578
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
89 { "command", "server-disconnect" },
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
90 { "server", "unknown" }
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
91 });
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
92
737
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
93 BOOST_TEST(code == server_error::not_found);
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
94 BOOST_TEST(json["error"].get<int>() == server_error::not_found);
190b16cfa848 Tests: improve command tests readability
David Demelier <markand@malikania.fr>
parents: 735
diff changeset
95 BOOST_TEST(json["errorCategory"].get<std::string>() == "server");
578
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
96 }
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
97
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
98 BOOST_AUTO_TEST_SUITE_END()
a8b892177909 Tests: add error code support in cmd-server-* tests
David Demelier <markand@malikania.fr>
parents: 558
diff changeset
99
558
f1ad428208d3 Tests: convert cmd-server-*, #593
David Demelier <markand@malikania.fr>
parents: 488
diff changeset
100 BOOST_AUTO_TEST_SUITE_END()
298
a67bc47e6d02 Tests: add test for server-disconnect and cnotice, #559
David Demelier <markand@malikania.fr>
parents:
diff changeset
101
723
e8c4ba5ed1c6 Tests: put code in anonymous namespaces, closes #889 @10m
David Demelier <markand@malikania.fr>
parents: 651
diff changeset
102 } // !namespace
e8c4ba5ed1c6 Tests: put code in anonymous namespaces, closes #889 @10m
David Demelier <markand@malikania.fr>
parents: 651
diff changeset
103
760
35c1517d705d Tests: make consistency
David Demelier <markand@malikania.fr>
parents: 757
diff changeset
104 } // !irccd