bin: consolidate clients
[awesomized/libmemcached] / test / tests / bin / memtouch.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/memtouch") {
10 Shell sh{string{TESTING_ROOT "/../src/bin"}};
11
12 SECTION("no servers provided") {
13 string output;
14 REQUIRE_FALSE(sh.run("memtouch", output));
15 REQUIRE(output == "No Servers provided\n");
16 }
17
18 SECTION("--help") {
19 string output;
20 REQUIRE(sh.run("memtouch --help", output));
21 REQUIRE_THAT(output, Contains("memtouch"));
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_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 = "memtouch --servers=localhost:" + to_string(port) + " ";
38
39 REQUIRE_SUCCESS(memcached_server_add(*memc, "localhost", port));
40
41 SECTION("found") {
42 REQUIRE_SUCCESS(memcached_set(*memc, S("memtouch"), S("memtouch-SET"), 0, 0));
43
44 string output;
45 REQUIRE(sh.run(comm + "memtouch", output));
46 REQUIRE(output.empty());
47 }
48
49 SECTION("not found") {
50 memcached_delete(*memc, S("memtouch"), 0);
51
52 string output;
53 REQUIRE_FALSE(sh.run(comm + "memtouch", output));
54 REQUIRE(output.empty());
55 }
56
57 SECTION("expires") {
58 REQUIRE_SUCCESS(memcached_set(*memc, S("memtouch"), S("memtouch"), 60, 0));
59 REQUIRE_SUCCESS(memcached_exist(*memc, S("memtouch")));
60 REQUIRE(sh.run(comm + "--expire=" + to_string(time(nullptr) - 2) + " memtouch"));
61 REQUIRE_RC(MEMCACHED_NOTFOUND, memcached_exist(*memc, S("memtouch")));
62 }
63 }
64 }