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/memrm") {
10 Shell sh
{string
{TESTING_ROOT
"/../src/bin"}};
12 SECTION("no servers provided") {
14 REQUIRE_FALSE(sh
.run("memrm", output
));
15 REQUIRE(output
== "No servers provided.\n");
20 REQUIRE(sh
.run("memrm --help", output
));
21 REQUIRE_THAT(output
, Contains("memrm v1"));
22 REQUIRE_THAT(output
, Contains("Usage:"));
23 REQUIRE_THAT(output
, Contains("key [key ...]"));
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"));
30 SECTION("with server") {
31 Server server
{MEMCACHED_BINARY
, {"-p", random_port_string
}};
33 LoneReturnMatcher test
{*memc
};
35 REQUIRE(server
.ensureListening());
36 auto port
= get
<int>(server
.getSocketOrPort());
37 auto comm
= "memrm --servers=localhost:" + to_string(port
) + " ";
39 REQUIRE_SUCCESS(memcached_server_add(*memc
, "localhost", port
));
41 SECTION("not found") {
43 REQUIRE_FALSE(sh
.run(comm
+ "-v key1", output
));
44 REQUIRE_THAT(output
, Contains("Could not find key 'key1'"));
45 REQUIRE_THAT(output
, Contains("NOT FOUND"));
50 REQUIRE_SUCCESS(memcached_set(*memc
, S("key1"), S("val1"), 0, 0));
51 REQUIRE_SUCCESS(memcached_set(*memc
, S("key2"), S("val2"), 0, 0));
53 this_thread::sleep_for(500ms
);
56 REQUIRE(sh
.run(comm
+ "key1", output
));
57 REQUIRE(output
.empty());
59 memcached_return_t rc
;
60 REQUIRE(nullptr == memcached_get(*memc
, S("key1"), nullptr, nullptr, &rc
));
61 REQUIRE_RC(MEMCACHED_NOTFOUND
, rc
);
62 Malloced
val(memcached_get(*memc
, S("key2"), nullptr, nullptr, &rc
));
67 SECTION("connection failure") {
68 server
.signal(SIGKILL
);
72 REQUIRE_FALSE(sh
.run(comm
+ " -v key2", output
));
74 Contains("CONNECTION FAILURE")
75 || Contains("SERVER HAS FAILED")
76 || Contains("SYSTEM ERROR")
77 || Contains("TIMEOUT OCCURRED"));