testing: honor MEMCACHED_BINARY; use Catch.cmake
[m6w6/libmemcached] / testing / tests / bin / memcat.cpp
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"
6
7 using Catch::Matchers::Contains;
8
9 TEST_CASE("bin/memcat") {
10 Shell sh{string{TESTING_ROOT "/../src/bin"}};
11
12 SECTION("no servers provided") {
13 string output;
14 REQUIRE_FALSE(sh.run("memcat", output));
15 REQUIRE(output == "No servers provided\n");
16 }
17
18 SECTION("--help") {
19 string output;
20 REQUIRE(sh.run("memcat --help", output));
21 REQUIRE_THAT(output, Contains("memcat"));
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("="));
28 }
29
30 SECTION("with server") {
31 Server server{MEMCACHED_BINARY, {"-p", random_port_string}};
32 MemcachedPtr memc;
33 LoneReturnMatcher test{*memc};
34
35 server.start();
36 Retry{[&server] { return server.isListening(); }}();
37 auto port = get<int>(server.getSocketOrPort());
38 auto comm = "memcat --servers=localhost:" + to_string(port) + " ";
39
40 REQUIRE_SUCCESS(memcached_server_add(*memc, "localhost", port));
41
42 SECTION("found") {
43 REQUIRE_SUCCESS(memcached_set(*memc, S("memcat"), S("MEMCAT-SET"), 0, 0));
44
45 string output;
46 REQUIRE(sh.run(comm + "memcat", output));
47 REQUIRE(output == "MEMCAT-SET\n");
48 }
49
50 SECTION("not found") {
51 memcached_delete(*memc, S("memcat"), 0);
52
53 string output;
54 REQUIRE_FALSE(sh.run(comm + "memcat", output));
55 REQUIRE_THAT(output, !Contains("MEMCAT-SET"));
56 REQUIRE_THAT(output, Contains("NOT FOUND"));
57 }
58 }
59 }