Skip to content

Commit

Permalink
* MDF [rest api test] format and enable mysql rest api
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 7, 2023
1 parent d23a084 commit 7b628f2
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions nanomq/tests/http_server_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,7 @@ test_post_rules()
{
assert(test_post_rules_repub());
assert(test_post_rules_sqlite());
// no mysql in ci env yet
// assert(test_post_rules_mysql());
assert(test_post_rules_mysql());
assert(test_post_rules_unsupported());
return true;
}
Expand Down Expand Up @@ -513,15 +512,18 @@ test_get_rule()
static bool
test_put_rule_repub()
{
char *cmd = "curl -i --basic -u admin_test:pw_test -XPUT "
"'http://localhost:8081/api/v4/rules/rule:3' "
"-d '{\"rawsql\":\"select * from \\\"t/b\\\"\","
"\"actions\": [{\"name\":\"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\", "
"\"proto_ver\": 4, \"keepalive\": 60}}]}'";
char *cmd =
"curl -i --basic -u admin_test:pw_test -XPUT "
"'http://localhost:8081/api/v4/rules/rule:3' "
"-d '{\"rawsql\":\"select * from \\\"t/b\\\"\","
"\"actions\": [{\"name\":\"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\", "
"\"proto_ver\": 4, \"keepalive\": 60}}]}'";
FILE *fd = popen(cmd, "r");
bool rv = check_http_return(fd, STATUS_CODE_OK, SUCCEED);
pclose(fd);
Expand All @@ -533,10 +535,10 @@ test_put_rule_sqlite()
{
char *cmd = "curl -i --basic -u admin_test:pw_test -XPUT "
"'http://localhost:8081/api/v4/rules/rule:4' "
"-d '{\"rawsql\":\"select * from \\\"t/b\\\"\","
"\"actions\": [{\"name\": \"sqlite\","
"\"params\": {\"table\": \"table_sqlite\"}}],"
"\"description\": \"sqlite-rule\"}'";
"-d '{\"rawsql\":\"select * from \\\"t/b\\\"\","
"\"actions\": [{\"name\": \"sqlite\","
"\"params\": {\"table\": \"table_sqlite\"}}],"
"\"description\": \"sqlite-rule\"}'";
// printf("cmd:%s\n", cmd);
FILE *fd = popen(cmd, "r");
bool rv = check_http_return(fd, STATUS_CODE_OK, SUCCEED);
Expand All @@ -549,10 +551,10 @@ test_put_rule_mysql()
{
char *cmd = "curl -i --basic -u admin_test:pw_test -XPUT "
"'http://localhost:8081/api/v4/rules/rule:2' "
"-d '{\"rawsql\":\"select * from \\\"t/b\\\"\","
"\"actions\": [{\"name\": \"mysql\","
"\"params\": {\"table\": \"table_mysql\"}}],"
"\"description\": \"mysql-rule\"}'";
"-d '{\"rawsql\":\"select * from \\\"t/b\\\"\","
"\"actions\": [{\"name\": \"mysql\","
"\"params\": {\"table\": \"table_mysql\"}}],"
"\"description\": \"mysql-rule\"}'";
FILE *fd = popen(cmd, "r");
bool rv = check_http_return(fd, STATUS_CODE_OK, SUCCEED);
pclose(fd);
Expand Down Expand Up @@ -805,7 +807,7 @@ main()
nng_msleep(100); // wait a while for broker to init
pid_sub = popen_sub_with_cmd(&outfp, cmd);
pid_sub2 = popen_sub_with_cmd(&outfp2, cmd2);
nng_msleep(50); // wait a while after sub
nng_msleep(500); // wait a while after sub

// TODO: there is a potential connection refuse case & although they
// work fine separately but if test_pub() is behind test_gets() there
Expand Down

0 comments on commit 7b628f2

Please sign in to comment.