From: Michael Wallner Date: Tue, 10 Nov 2020 13:06:57 +0000 (+0100) Subject: testing: memcat X-Git-Tag: 1.1.0-beta1~118 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=582d5c93bcd01e2b44ce41dd81094cb20317caaf;p=m6w6%2Flibmemcached testing: memcat --- diff --git a/ChangeLog-1.1.md b/ChangeLog-1.1.md index ada84c86..2d5846a7 100644 --- a/ChangeLog-1.1.md +++ b/ChangeLog-1.1.md @@ -102,6 +102,7 @@ was incremented due to the following changes: clarify documentation on replication. * Fix [gh #95](https://github.com/m6w6/libmemcached/issues/95): MEMCACHED_CALLBACK_GET_FAILURE and MEMCACHED_BEHAVIOR_BUFFER_REQUESTS +* Fix bin/memcat to output flags if requested with `--flag`. --- diff --git a/src/bin/memcat.cc b/src/bin/memcat.cc index 84de35ed..50e21395 100644 --- a/src/bin/memcat.cc +++ b/src/bin/memcat.cc @@ -97,8 +97,9 @@ int main(int argc, char *argv[]) { if (rc == MEMCACHED_SUCCESS) { if (opt_displayflag) { if (opt_verbose) { - std::cout << "key: " << argv[optind] << std::endl << "flags: " << flags << std::endl; + std::cout << "key: " << argv[optind] << std::endl << "flags: "; } + std::cout << flags << std::endl; } else { if (opt_verbose) { std::cout << "key: " << argv[optind] << std::endl diff --git a/test/lib/common.hpp b/test/lib/common.hpp index 8942a729..e522f9cc 100644 --- a/test/lib/common.hpp +++ b/test/lib/common.hpp @@ -90,6 +90,17 @@ public: bool put(const char *buf, size_t len) const { return static_cast(len) == write(fd, buf, len); } + string get() const { + string all; + char buf[200]; + ssize_t len; + + lseek(fd, 0, SEEK_SET); + while (0 < (len = read(fd, buf, sizeof(buf)))) { + all.append(buf, len); + } + return all; + } private: char fn[80]; diff --git a/test/tests/bin/memcat.cpp b/test/tests/bin/memcat.cpp index 4e91617e..b7390aea 100644 --- a/test/tests/bin/memcat.cpp +++ b/test/tests/bin/memcat.cpp @@ -15,6 +15,12 @@ TEST_CASE("bin/memcat") { REQUIRE(output == "No servers provided\n"); } + SECTION("connection failure") { + string output; + CHECK_FALSE(sh.run("memcat --servers=localhost:" + random_port_string("-p") + " memcat", output)); + REQUIRE_THAT(output, Contains("CONNECTION FAILURE")); + } + SECTION("--help") { string output; REQUIRE(sh.run("memcat --help", output)); @@ -38,14 +44,6 @@ TEST_CASE("bin/memcat") { REQUIRE_SUCCESS(memcached_server_add(*memc, "localhost", port)); - SECTION("found") { - REQUIRE_SUCCESS(memcached_set(*memc, S("memcat"), S("MEMCAT-SET"), 0, 0)); - - string output; - REQUIRE(sh.run(comm + "memcat", output)); - REQUIRE(output == "MEMCAT-SET\n"); - } - SECTION("not found") { memcached_delete(*memc, S("memcat"), 0); @@ -54,5 +52,27 @@ TEST_CASE("bin/memcat") { REQUIRE_THAT(output, !Contains("MEMCAT-SET")); REQUIRE_THAT(output, Contains("NOT FOUND")); } + SECTION("found") { + string output; + REQUIRE_SUCCESS(memcached_set(*memc, S("memcat"), S("MEMCAT-SET"), 0, 123)); + + SECTION("default") { + REQUIRE(sh.run(comm + "memcat", output)); + REQUIRE(output == "MEMCAT-SET\n"); + } + SECTION("flags") { + REQUIRE(sh.run(comm + "--flag memcat", output)); + REQUIRE(output == "123\n"); + output.clear(); + REQUIRE(sh.run(comm + "--flag -v memcat", output)); + REQUIRE(output == "key: memcat\nflags: 123\n"); + } + SECTION("file") { + Tempfile temp; + REQUIRE(sh.run(comm + "--file " + temp.getFn() + " memcat", output)); + REQUIRE(output.empty()); + REQUIRE(temp.get() == "MEMCAT-SET"); + } + } } }