update TODO
[awesomized/libmemcached] / test / tests / bin / memdump.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/Shell.hpp"
3 #include "test/lib/Server.hpp"
4 #include "test/lib/Retry.hpp"
5 #include "test/lib/ReturnMatcher.hpp"
6
7 using Catch::Matchers::Contains;
8
9 TEST_CASE("bin/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 v1"));
22 REQUIRE_THAT(output, Contains("Usage:"));
23 REQUIRE_THAT(output, Contains("Options:"));
24 REQUIRE_THAT(output, Contains("-h|--help"));
25 REQUIRE_THAT(output, Contains("-V|--version"));
26 REQUIRE_THAT(output, Contains("Environment:"));
27 REQUIRE_THAT(output, Contains("MEMCACHED_SERVERS"));
28 }
29
30 SECTION("with server") {
31 Server server{MEMCACHED_BINARY, {"-p", random_port_string}};
32 MemcachedPtr memc;
33 LoneReturnMatcher test{*memc};
34
35 REQUIRE(server.ensureListening());
36 auto port = get<int>(server.getSocketOrPort());
37 auto comm = "memdump --servers=localhost:" + to_string(port) + " ";
38
39 REQUIRE_SUCCESS(memcached_server_add(*memc, "localhost", port));
40
41 SECTION("okay") {
42
43 REQUIRE_SUCCESS(memcached_set(*memc, S("key1"), S("val1"), 0, 0));
44 REQUIRE_SUCCESS(memcached_set(*memc, S("key2"), S("val2"), 0, 0));
45
46 this_thread::sleep_for(500ms);
47
48 string output;
49 REQUIRE(sh.run(comm, output));
50 REQUIRE_THAT(output, Contains("key1") && Contains("key2"));
51 }
52
53 SECTION("connection failure") {
54 server.signal(SIGKILL);
55 server.wait();
56
57 string output;
58 REQUIRE_FALSE(sh.run(comm + "-v", output));
59 REQUIRE_THAT(output,
60 Contains("CONNECTION FAILURE")
61 || Contains("SERVER HAS FAILED")
62 || Contains("SYSTEM ERROR")
63 || Contains("TIMEOUT OCCURRED"));
64 }
65
66 SECTION("empty") {
67 string output;
68 REQUIRE(sh.run(comm, output));
69 REQUIRE(output == "");
70 }
71 }
72 }