1 #include "testing/lib/common.hpp"
2 #include "testing/lib/Shell.hpp"
3 #include "testing/lib/Server.hpp"
4 #include "testing/lib/Retry.hpp"
5 #include "testing/lib/ReturnMatcher.hpp"
7 using Catch::Matchers::Contains
;
9 TEST_CASE("bin/memexist") {
10 Shell sh
{string
{TESTING_ROOT
"/../src/bin"}};
12 SECTION("no servers provided") {
14 REQUIRE_FALSE(sh
.run("memexist", output
));
15 REQUIRE(output
== "No Servers provided\n");
20 REQUIRE(sh
.run("memexist --help", output
));
21 REQUIRE_THAT(output
, Contains("memexist"));
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("="));
30 SECTION("with server") {
31 Server server
{MEMCACHED_BINARY
, {"-p", random_port_string
}};
33 LoneReturnMatcher test
{*memc
};
36 Retry
{[&server
] { return server
.isListening(); }}();
37 auto port
= get
<int>(server
.getSocketOrPort());
38 auto comm
= "memexist --servers=localhost:" + to_string(port
) + " ";
40 REQUIRE_SUCCESS(memcached_server_add(*memc
, "localhost", port
));
43 REQUIRE_SUCCESS(memcached_set(*memc
, S("memexist"), S("MEMEXIST-SET"), 0, 0));
46 REQUIRE(sh
.run(comm
+ "memexist", output
));
47 REQUIRE(output
.empty());
50 SECTION("not found") {
51 memcached_delete(*memc
, S("memexist"), 0);
54 REQUIRE_FALSE(sh
.run(comm
+ "memexist", output
));
55 REQUIRE(output
.empty());