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/memcp") {
10 Shell sh
{string
{TESTING_ROOT
"/../src/bin"}};
12 SECTION("no servers provided") {
14 REQUIRE_FALSE(sh
.run("memcp nonexistent", output
));
15 REQUIRE(output
== "No servers provided.\n");
20 REQUIRE(sh
.run("memcp --help", output
));
21 REQUIRE_THAT(output
, Contains("memcp v1"));
22 REQUIRE_THAT(output
, Contains("Usage:"));
23 REQUIRE_THAT(output
, Contains("file [file ...]"));
24 REQUIRE_THAT(output
, Contains("Options:"));
25 REQUIRE_THAT(output
, Contains("-h|--help"));
26 REQUIRE_THAT(output
, Contains("-V|--version"));
27 REQUIRE_THAT(output
, Contains("Environment:"));
28 REQUIRE_THAT(output
, Contains("MEMCACHED_SERVERS"));
31 SECTION("with server") {
32 Server server
{MEMCACHED_BINARY
, {"-U", random_port_string
}};
34 LoneReturnMatcher test
{*memc
};
36 REQUIRE(server
.ensureListening());
37 auto port
= get
<int>(server
.getSocketOrPort());
38 auto comm
= "memcp --servers=localhost:" + to_string(port
) + " ";
40 REQUIRE_SUCCESS(memcached_server_add(*memc
, "localhost", port
));
43 auto udp_buffer
= GENERATE(0,1,2);
44 auto binary
= GENERATE(0,1);
45 auto set_add_replace
= GENERATE(0,1,2);
46 auto expire
= GENERATE(0, random_num(10,12345));
47 string set_add_replace_s
[3] = {
48 "set", "add", "replace"
51 DYNAMIC_SECTION("udp=" << (udp_buffer
==1) <<" buffer=" << (udp_buffer
==2) << " binary=" << binary
<< " mode=" << set_add_replace_s
[set_add_replace
] << " expire=" << expire
) {
55 if (udp_buffer
== 1) {
57 } else if (udp_buffer
== 2) {
64 comm
+= " --expire " + to_string(expire
) + " ";
66 switch (set_add_replace
) {
68 comm
+= " --replace ";
69 REQUIRE_SUCCESS(memcached_set(*memc
, S(temp
.getFn()), S("foo"), 0, 0));
77 auto ok
= sh
.run(comm
+ temp
.getFn(), output
);
78 REQUIRE(output
== "");
81 Retry settled
{[&memc
, &temp
]{
83 memcached_return_t rc
;
84 Malloced
val(memcached_get(*memc
, S(temp
.getFn()), &len
, nullptr, &rc
));
86 return MEMCACHED_SUCCESS
== rc
&& *val
&& string(*val
, len
) == "123";
92 SECTION("connection failure") {
93 server
.signal(SIGKILL
);
99 REQUIRE_FALSE(sh
.run(comm
+ temp
.getFn(), output
));
101 Contains("CONNECTION FAILURE")
102 || Contains("SERVER HAS FAILED")
103 || Contains("SYSTEM ERROR")
104 || Contains("TIMEOUT OCCURRED"));
107 SECTION("file not found") {
109 REQUIRE_FALSE(sh
.run(comm
+ "nonexistent", output
));
110 REQUIRE_THAT(output
, Contains("No such file or directory"));