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/memcat") {
10 Shell sh
{string
{TESTING_ROOT
"/../src/bin"}};
12 SECTION("no servers provided") {
14 REQUIRE_FALSE(sh
.run("memcat", output
));
15 REQUIRE(output
== "No servers provided\n");
18 SECTION("connection failure") {
20 CHECK_FALSE(sh
.run("memcat --servers=localhost:" + random_port_string("-p") + " memcat", output
));
21 REQUIRE_THAT(output
, Contains("CONNECTION FAILURE"));
26 REQUIRE(sh
.run("memcat --help", output
));
27 REQUIRE_THAT(output
, Contains("memcat"));
28 REQUIRE_THAT(output
, Contains("v1"));
29 REQUIRE_THAT(output
, Contains("help"));
30 REQUIRE_THAT(output
, Contains("version"));
31 REQUIRE_THAT(output
, Contains("option"));
32 REQUIRE_THAT(output
, Contains("--"));
33 REQUIRE_THAT(output
, Contains("="));
36 SECTION("with server") {
37 Server server
{MEMCACHED_BINARY
, {"-p", random_port_string
}};
39 LoneReturnMatcher test
{*memc
};
41 REQUIRE(server
.ensureListening());
42 auto port
= get
<int>(server
.getSocketOrPort());
43 auto comm
= "memcat --servers=localhost:" + to_string(port
) + " ";
45 REQUIRE_SUCCESS(memcached_server_add(*memc
, "localhost", port
));
47 SECTION("not found") {
48 memcached_delete(*memc
, S("memcat"), 0);
51 REQUIRE_FALSE(sh
.run(comm
+ "memcat", output
));
52 REQUIRE_THAT(output
, !Contains("MEMCAT-SET"));
53 REQUIRE_THAT(output
, Contains("NOT FOUND"));
57 REQUIRE_SUCCESS(memcached_set(*memc
, S("memcat"), S("MEMCAT-SET"), 0, 123));
60 REQUIRE(sh
.run(comm
+ "memcat", output
));
61 REQUIRE(output
== "MEMCAT-SET\n");
64 REQUIRE(sh
.run(comm
+ "--flag memcat", output
));
65 REQUIRE(output
== "123\n");
67 REQUIRE(sh
.run(comm
+ "--flag -v memcat", output
));
68 REQUIRE(output
== "key: memcat\nflags: 123\n");
72 REQUIRE(sh
.run(comm
+ "--file " + temp
.getFn() + " memcat", output
));
73 REQUIRE(output
.empty());
74 REQUIRE(temp
.get() == "MEMCAT-SET");