Skip to content

Commit

Permalink
regression test for host parse
Browse files Browse the repository at this point in the history
  • Loading branch information
kentslaney committed Nov 28, 2023
1 parent e54938f commit 316a68e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 0 additions & 1 deletion libmc/_client.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ cdef class PyClient:
Py_INCREF(servers_)
for i in range(n):
c_split = splitServerString(servers_[i])
host, port, alias = c_split

c_hosts[i] = c_split.host
c_ports[i] = MC_DEFAULT_PORT if c_split.port == NULL else atoi(c_split.port)
Expand Down
5 changes: 3 additions & 2 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ ServerSpec splitServerString(char* input) {
for (;;) {
switch (*(++input))
{
case '\0':
return res;
case ':': // invalid in a UNIX path
*input = '\0';
res.port = input + 1;
num = true;
case '\0':
return res;
continue;
case ' ':
if (!escaped) {
*input = '\0';
Expand Down
11 changes: 11 additions & 0 deletions tests/test_unix.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "Common.h"
#include "Client.h"
#include "test_common.h"

Expand All @@ -6,9 +7,19 @@

using douban::mc::Client;
using douban::mc::tests::newUnixClient;
using douban::mc::splitServerString;
using douban::mc::ServerSpec;

TEST(test_unix, establish_connection) {
Client* client = newUnixClient();
EXPECT_TRUE(client != NULL);
delete client;
}

TEST(test_unix, host_parse_regression) {
char test[] = "127.0.0.1:21211 testing";
ServerSpec out = splitServerString(test);
ASSERT_STREQ(out.host, "127.0.0.1");
ASSERT_STREQ(out.port, "21211");
ASSERT_STREQ(out.alias, "testing");
}

0 comments on commit 316a68e

Please sign in to comment.