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"
7 using Catch::Matchers::Contains
;
9 TEST_CASE("bin/memtouch") {
10 Shell sh
{string
{TESTING_ROOT
"/../src/bin"}};
12 SECTION("no servers provided") {
14 REQUIRE_FALSE(sh
.run("memtouch", output
));
15 REQUIRE(output
== "No servers provided.\n");
20 REQUIRE(sh
.run("memtouch --help", output
));
21 REQUIRE_THAT(output
, Contains("memtouch v1"));
22 REQUIRE_THAT(output
, Contains("Usage:"));
23 REQUIRE_THAT(output
, Contains("key [key ...]"));
24 REQUIRE_THAT(output
, Contains("Options:"));
25 REQUIRE_THAT(output
, Contains("-h|--help"));
26 REQUIRE_THAT(output
, Contains("-V|--version"));
27 REQUIRE_THAT(output
, Contains("Environment:"));
28 REQUIRE_THAT(output
, Contains("MEMCACHED_SERVERS"));
31 SECTION("with server") {
32 Server server
{MEMCACHED_BINARY
, {"-p", random_port_string
}};
34 LoneReturnMatcher test
{*memc
};
36 REQUIRE(server
.ensureListening());
37 auto port
= get
<int>(server
.getSocketOrPort());
38 auto comm
= "memtouch --servers=localhost:" + to_string(port
) + " ";
40 REQUIRE_SUCCESS(memcached_server_add(*memc
, "localhost", port
));
43 REQUIRE_SUCCESS(memcached_set(*memc
, S("memtouch"), S("memtouch-SET"), 0, 0));
46 REQUIRE(sh
.run(comm
+ "memtouch", output
));
47 REQUIRE(output
.empty());
50 SECTION("not found") {
51 memcached_delete(*memc
, S("memtouch"), 0);
54 REQUIRE_FALSE(sh
.run(comm
+ "memtouch", output
));
55 REQUIRE(output
.empty());
59 REQUIRE_SUCCESS(memcached_set(*memc
, S("memtouch"), S("memtouch"), 60, 0));
60 REQUIRE_SUCCESS(memcached_exist(*memc
, S("memtouch")));
62 bool ok
= sh
.run(comm
+ " -v --expire=" + to_string(time(nullptr) - 2) + " memtouch", output
);
63 REQUIRE(output
== "");
65 REQUIRE_RC(MEMCACHED_NOTFOUND
, memcached_exist(*memc
, S("memtouch")));