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