Skip to content

Commit

Permalink
* NEW [test] more tests for http api post rules
Browse files Browse the repository at this point in the history
Signed-off-by: Hermann0222 <yukang.wei@emqx.io>
  • Loading branch information
OdyWayne committed Nov 2, 2023
1 parent 0e5066f commit c161184
Showing 1 changed file with 66 additions and 5 deletions.
71 changes: 66 additions & 5 deletions nanomq/tests/http_server_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ test_put_bridges_unsub()
}

static bool
test_post_rules()
test_post_rules_repub()
{
char *cmd =
"curl -i --basic -u admin_test:pw_test "
Expand All @@ -419,15 +419,76 @@ test_post_rules()
"\"repub\", \"params\": { \"topic\": \"repub1\", "
"\"address\":\"mqtt-tcp://localhost:1881\", \"clean_start\": "
"\"true\", "
// TODO: there is a memleak in nanoclient connmsg sending.
// "\"clientid\": \"id\", \"username\": \"admin\", \"password\":"
// "\"public\", "
"\"clientid\": \"id\", \"username\": \"admin\", \"password\":"
"\"public\", "
"\"proto_ver\": 4, \"keepalive\": 60 } }], "
"\"description\": \"repub-rule\"}'";
FILE *fd = popen(cmd, "r");
bool rv = check_http_return(fd, STATUS_CODE_OK, SUCCEED);
pclose(fd);
return rv;
return rv;
}

static bool
test_post_rules_sqlite()
{
char *cmd =
"curl -i --basic -u admin_test:pw_test "
"'http://localhost:8081/api/v4/rules' -X POST -d '{ \"rawsql\": "
"\"select * from \\\"t/b\\\"\", \"actions\": [{ \"name\": "
"\"sqlite\", \"params\": { \"table\": \"broker1\"} }], "
"\"description\": \"sqlite-rule\"}'";
FILE *fd = popen(cmd, "r");
bool rv = check_http_return(fd, STATUS_CODE_OK, SUCCEED);
pclose(fd);
return rv;
}

static bool
test_post_rules_mysql()
{
char *cmd =
"curl -i --basic -u admin_test:pw_test "
"'http://localhost:8081/api/v4/rules' -X POST -d '{ \"rawsql\": "
"\"select * from \\\"t/c\\\"\", \"actions\": [{ \"name\": "
"\"mysql\", \"params\": { \"table\": \"broker1\", "
"\"username\":\"username\", \"password\": \"password\", "
"\"host\": \"localhost\"} }], "
"\"description\": \"mysql-rule\"}'";
FILE *fd = popen(cmd, "r");
bool rv = check_http_return(fd, STATUS_CODE_OK, SUCCEED);
pclose(fd);
return rv;
}

static bool
test_post_rules_unsupported()
{
char *cmd =
"curl -i --basic -u admin_test:pw_test "
"'http://localhost:8081/api/v4/rules' -X POST -d '{ \"rawsql\": "
"\"select * from \\\"t/d\\\"\", \"actions\": [{ \"name\": "
"\"mesql\", \"params\": { \"topic\": \"mesql1\", "
"\"address\":\"mqtt-tcp://localhost:1881\", \"clean_start\": "
"\"true\", "
"\"clientid\": \"id\", \"username\": \"admin\", \"password\":"
"\"public\", "
"\"proto_ver\": 4, \"keepalive\": 60 } }], "
"\"description\": \"unsup-rule\"}'";
FILE *fd = popen(cmd, "r");
bool rv = check_http_return(fd, STATUS_CODE_BAD_REQUEST, PLUGIN_IS_CLOSED);
pclose(fd);
return rv;
}

static bool
test_post_rules()
{
assert(test_post_rules_repub());
assert(test_post_rules_sqlite());
assert(test_post_rules_mysql());
assert(test_post_rules_unsupported());
return true;
}

static bool
Expand Down

0 comments on commit c161184

Please sign in to comment.