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"));
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
, {"-U", random_port_string
}};
33 LoneReturnMatcher test
{*memc
};
35 REQUIRE(server
.ensureListening());
36 auto port
= get
<int>(server
.getSocketOrPort());
37 auto comm
= "memcp --servers=localhost:" + to_string(port
) + " ";
39 REQUIRE_SUCCESS(memcached_server_add(*memc
, "localhost", port
));
42 auto udp_buffer
= GENERATE(0,1,2);
43 auto binary
= GENERATE(0,1);
44 auto set_add_replace
= GENERATE(0,1,2);
45 auto expire
= GENERATE(0, random_num(10,12345));
46 string set_add_replace_s
[3] = {
47 "set", "add", "replace"
50 DYNAMIC_SECTION("udp=" << (udp_buffer
==1) <<" buffer=" << (udp_buffer
==2) << " binary=" << binary
<< " mode=" << set_add_replace_s
[set_add_replace
] << " expire=" << expire
) {
54 if (udp_buffer
== 1) {
56 } else if (udp_buffer
== 2) {
63 comm
+= " --expire " + to_string(expire
) + " ";
65 switch (set_add_replace
) {
67 comm
+= " --replace ";
68 REQUIRE_SUCCESS(memcached_set(*memc
, S(temp
.getFn()), S("foo"), 0, 0));
76 auto ok
= sh
.run(comm
+ temp
.getFn(), output
);
77 REQUIRE(output
== "");
80 Retry settled
{[&memc
, &temp
]{
82 memcached_return_t rc
;
83 Malloced
val(memcached_get(*memc
, S(temp
.getFn()), &len
, nullptr, &rc
));
85 return MEMCACHED_SUCCESS
== rc
&& *val
&& string(*val
, len
) == "123";
91 SECTION("connection failure") {
92 server
.signal(SIGKILL
);
98 REQUIRE_FALSE(sh
.run(comm
+ temp
.getFn(), output
));
100 Contains("CONNECTION FAILURE")
101 || Contains("SERVER HAS FAILED")
102 || Contains("SYSTEM ERROR")
103 || Contains("TIMEOUT OCCURRED"));
106 SECTION("file not found") {
108 REQUIRE_FALSE(sh
.run(comm
+ "nonexistent", output
));
109 REQUIRE_THAT(output
, Contains("No such file or directory"));