fe3023350243afe875687965be0a01e9aac1c6da
[awesomized/libmemcached] / testing / tests / bin / memdump.cpp
1 #include "testing/lib/common.hpp"
2 #include "testing/lib/Shell.hpp"
3 #include "testing/lib/Server.hpp"
4 #include "testing/lib/Retry.hpp"
5 #include "testing/lib/ReturnMatcher.hpp"
6
7 using Catch::Matchers::Contains;
8
9 TEST_CASE("memdump") {
10 Shell sh{string{TESTING_ROOT "/../src/bin"}};
11
12 SECTION("no servers provided") {
13 string output;
14 REQUIRE_FALSE(sh.run("memdump", output));
15 REQUIRE(output == "No Servers provided\n");
16 }
17
18 SECTION("--help") {
19 string output;
20 REQUIRE(sh.run("memdump --help", output));
21 REQUIRE_THAT(output, Contains("memdump"));
22 REQUIRE_THAT(output, Contains("v1"));
23 REQUIRE_THAT(output, Contains("help"));
24 REQUIRE_THAT(output, Contains("version"));
25 REQUIRE_THAT(output, Contains("option"));
26 REQUIRE_THAT(output, Contains("--"));
27 REQUIRE_THAT(output, Contains("="));
28 }
29
30 SECTION("with server") {
31 Server server{"memcached"};
32 MemcachedPtr memc;
33 LoneReturnMatcher test{*memc};
34
35 server.start();
36 Retry{[&server] { return server.isListening(); }}();
37 auto port = get<int>(server.getSocketOrPort());
38 auto comm = "memdump --servers=localhost:" + to_string(port) + " ";
39
40 REQUIRE_SUCCESS(memcached_server_add(*memc, "localhost", port));
41
42 SECTION("okay") {
43
44 REQUIRE_SUCCESS(memcached_set(*memc, S("key1"), S("val1"), 0, 0));
45 REQUIRE_SUCCESS(memcached_set(*memc, S("key2"), S("val2"), 0, 0));
46
47 string output;
48 REQUIRE(sh.run(comm, output));
49 REQUIRE_THAT(output, Contains("key1") && Contains("key2"));
50 }
51
52 SECTION("connection failure") {
53 server.signal(SIGKILL);
54
55 string output;
56 REQUIRE_FALSE(sh.run(comm + "-v", output));
57 REQUIRE_THAT(output, Contains("CONNECTION FAILURE") || Contains("SERVER HAS FAILED"));
58 }
59
60 SECTION("empty") {
61 string output;
62 REQUIRE(sh.run(comm, output));
63 REQUIRE(output == "");
64 }
65 }
66 }