wip Update
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
NADAL Jean-Baptiste
2020-01-24 18:27:42 +01:00
parent ce452dd4b8
commit 013d541769
3 changed files with 604 additions and 10 deletions

View File

@@ -77,6 +77,7 @@ int my_success_rest_delete_handler(short event, restd_conn_t *conn, void *userda
int my_success_rest_put_handler(short event, restd_conn_t *conn, void *userdata)
{
printf("put event: %d\n", event);
restd_http_response(conn, 200, "application/json", ksuccess_put_body, strlen(ksuccess_put_body));
return RESTD_CLOSE; // Close connection.
}
@@ -115,7 +116,7 @@ size_t write_callback(void *ptr, size_t size, size_t nmemb, void *stream)
int exec_request(const char *request, const char *path, int expected_code, const char *expected_body)
{
int ret;
int ret = 0;
CURL *curl_handle;
CURLcode res;
char *body = NULL;
@@ -150,7 +151,7 @@ int exec_request(const char *request, const char *path, int expected_code, const
}
// Debug Only
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
//curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
/* send all data to this function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_callback);
@@ -159,15 +160,25 @@ int exec_request(const char *request, const char *path, int expected_code, const
/* get it! */
res = curl_easy_perform(curl_handle);
if (res != CURLE_OK)
{
printf("Error: %d\n", res);
}
ASSERT_EQUAL_INT(res, CURLE_OK);
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_result_code);
ASSERT_EQUAL_INT(http_result_code, expected_code);
res = strcmp(expected_body, body);
//printf ("body: %s != expected_body: %s\n", body, expected_body);
if (res != 0)
{
ret = 2;
goto exit;
}
ASSERT_EQUAL_INT(res, 0);
exit:
free(body);
/* cleanup curl stuff */
@@ -176,7 +187,7 @@ int exec_request(const char *request, const char *path, int expected_code, const
/* we're done with libcurl, so clean it up */
curl_global_cleanup();
return 0;
return ret;
}
/*--------------------------------------------------------------------------*/
@@ -406,14 +417,17 @@ TEST("Rest - create start access rest hook free\t")
sleep(1);
PRINTLN("\n - GET");
ret = exec_request(kget_method, "http://localhost:"kserver_port kapi_test_get, 200, ksuccess_get_body);
ASSERT_EQUAL_INT(ret, 0);
PRINTLN("\n - DELETE");
ret = exec_request(kdelete_method, "http://localhost:"kserver_port kapi_test_get, 200, ksuccess_delete_body);
ASSERT_EQUAL_INT(ret, 0);
//ret = exec_request(kput_method, "http://localhost:"kserver_port kapi_test_get, 200, ksuccess_put_body);
//ASSERT_EQUAL_INT(ret, 0);
PRINTLN("\n - PUT");
ret = exec_request(kput_method, "http://localhost:"kserver_port kapi_test_get, 200, ksuccess_put_body);
ASSERT_EQUAL_INT(ret, 0);
// TODO POST