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 v1"));
28 REQUIRE_THAT(output
, Contains("Usage:"));
29 REQUIRE_THAT(output
, Contains("key [key ...]"));
30 REQUIRE_THAT(output
, Contains("Options:"));
31 REQUIRE_THAT(output
, Contains("-h|--help"));
32 REQUIRE_THAT(output
, Contains("-V|--version"));
33 REQUIRE_THAT(output
, Contains("Environment:"));
34 REQUIRE_THAT(output
, Contains("MEMCACHED_SERVERS"));
37 SECTION("with server") {
38 Server server
{MEMCACHED_BINARY
, {"-p", random_port_string
}};
40 LoneReturnMatcher test
{*memc
};
42 REQUIRE(server
.ensureListening());
43 auto port
= get
<int>(server
.getSocketOrPort());
44 auto comm
= "memcat --servers=localhost:" + to_string(port
) + " ";
46 REQUIRE_SUCCESS(memcached_server_add(*memc
, "localhost", port
));
48 SECTION("not found") {
49 memcached_delete(*memc
, S("memcat"), 0);
52 REQUIRE_FALSE(sh
.run(comm
+ "memcat", output
));
53 REQUIRE(output
.empty());
55 SECTION("not found --verbose") {
56 memcached_delete(*memc
, S("memcat"), 0);
59 REQUIRE_FALSE(sh
.run(comm
+ " -v memcat", output
));
60 REQUIRE_THAT(output
, !Contains("MEMCAT-SET"));
61 REQUIRE_THAT(output
, Contains("NOT FOUND"));
65 REQUIRE_SUCCESS(memcached_set(*memc
, S("memcat"), S("MEMCAT-SET"), 0, 123));
68 REQUIRE(sh
.run(comm
+ "memcat", output
));
69 REQUIRE(output
== "MEMCAT-SET\n");
72 REQUIRE(sh
.run(comm
+ "--flag memcat", output
));
73 REQUIRE(output
== "123\nMEMCAT-SET\n");
75 REQUIRE(sh
.run(comm
+ "--flag -v memcat", output
));
76 REQUIRE(output
== "key: memcat\nflags: 123\nvalue: MEMCAT-SET\n");
80 REQUIRE(sh
.run(comm
+ "--file " + temp
.getFn() + " memcat", output
));
81 REQUIRE(output
.empty());
82 REQUIRE(temp
.get() == "MEMCAT-SET");