bin: consolidate clients
[awesomized/libmemcached] / test / tests / bin / memcp.cpp
index 83fe974969b25d1debc975a36833415b7f513c9b..c3fa788466461652b47a1d3a4438db62031a23d3 100644 (file)
@@ -12,23 +12,24 @@ TEST_CASE("bin/memcp") {
   SECTION("no servers provided") {
     string output;
     REQUIRE_FALSE(sh.run("memcp nonexistent", output));
-    REQUIRE(output == "No Servers provided\n");
+    REQUIRE(output == "No servers provided.\n");
   }
 
   SECTION("--help") {
     string output;
     REQUIRE(sh.run("memcp --help", output));
-    REQUIRE_THAT(output, Contains("memcp"));
-    REQUIRE_THAT(output, Contains("v1"));
-    REQUIRE_THAT(output, Contains("help"));
-    REQUIRE_THAT(output, Contains("version"));
-    REQUIRE_THAT(output, Contains("option"));
-    REQUIRE_THAT(output, Contains("--"));
-    REQUIRE_THAT(output, Contains("="));
+    REQUIRE_THAT(output, Contains("memcp v1"));
+    REQUIRE_THAT(output, Contains("Usage:"));
+    REQUIRE_THAT(output, Contains("file [file ...]"));
+    REQUIRE_THAT(output, Contains("Options:"));
+    REQUIRE_THAT(output, Contains("-h|--help"));
+    REQUIRE_THAT(output, Contains("-V|--version"));
+    REQUIRE_THAT(output, Contains("Environment:"));
+    REQUIRE_THAT(output, Contains("MEMCACHED_SERVERS"));
   }
 
   SECTION("with server") {
-    Server server{MEMCACHED_BINARY, {"-p", random_port_string}};
+    Server server{MEMCACHED_BINARY, {"-U", random_port_string}};
     MemcachedPtr memc;
     LoneReturnMatcher test{*memc};
 
@@ -39,20 +40,53 @@ TEST_CASE("bin/memcp") {
     REQUIRE_SUCCESS(memcached_server_add(*memc, "localhost", port));
 
     SECTION("okay") {
-      Tempfile temp;
-      temp.put(S("123"));
+      auto udp_buffer = GENERATE(0,1,2);
+      auto binary = GENERATE(0,1);
+      auto set_add_replace = GENERATE(0,1,2);
+      auto expire = GENERATE(0, random_num(10,12345));
+      string set_add_replace_s[3] = {
+          "set", "add", "replace"
+      };
 
-      string output;
-      REQUIRE(sh.run(comm + temp.getFn(), output));
-      REQUIRE(output == "");
+      DYNAMIC_SECTION("udp=" << (udp_buffer==1) <<" buffer=" << (udp_buffer==2) << " binary=" << binary <<  " mode=" << set_add_replace_s[set_add_replace] << " expire=" << expire) {
+        Tempfile temp;
+        temp.put(S("123"));
+
+        if (udp_buffer == 1) {
+          comm += " --udp ";
+        } else if (udp_buffer == 2) {
+          comm += " --buffer ";
+        }
+        if(binary) {
+          comm += " --binary ";
+        }
+        if (expire) {
+          comm += " --expire " + to_string(expire) + " ";
+        }
+        switch (set_add_replace) {
+        case 2:
+          comm += " --replace ";
+          REQUIRE_SUCCESS(memcached_set(*memc, S(temp.getFn()), S("foo"), 0, 0));
+          break;
+        case 1:
+          comm += " --add ";
+        }
+
+        INFO(comm);
+        string output;
+        auto ok = sh.run(comm + temp.getFn(), output);
+        REQUIRE(output == "");
+        REQUIRE(ok);
 
-      size_t len;
-      memcached_return_t rc;
-      Malloced val(memcached_get(*memc, S(temp.getFn()), &len, nullptr, &rc));
+        Retry settled{[&memc, &temp]{
+          size_t len;
+          memcached_return_t rc;
+          Malloced val(memcached_get(*memc, S(temp.getFn()), &len, nullptr, &rc));
 
-      REQUIRE(*val);
-      REQUIRE_SUCCESS(rc);
-      REQUIRE(string(*val, len) == "123");
+          return MEMCACHED_SUCCESS == rc && *val && string(*val, len) == "123";
+        }};
+        REQUIRE(settled());
+      }
     }
 
     SECTION("connection failure") {