Skip to content

Commit

Permalink
tests: runtime: in_calyptia_fleet: update mock server
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Stephens <[email protected]>
  • Loading branch information
patrick-stephens committed Dec 16, 2024
1 parent e302b5b commit 86bf6d4
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions tests/runtime/in_calyptia_fleet_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static void mock_server_fleet_files_toml(mk_request_t *request, void *data)
{
tomlRequests++;
/* Use a local buffer with correct size */
char *response = "{\"id\":\"test-id\"}";
char *response = "{\"id\":\"test_fleet_id\"}";
size_t response_len = strlen(response);

mk_http_status(request, 200);
Expand All @@ -148,7 +148,7 @@ static void mock_server_fleet_files_yaml(mk_request_t *request, void *data)
{
yamlRequests++;
/* Use a local buffer with correct size */
char *response = "{\"id\":\"test-id\"}";
char *response = "{\"id\":\"test_fleet_id\"}";
size_t response_len = strlen(response);

mk_http_status(request, 200);
Expand All @@ -158,6 +158,20 @@ static void mock_server_fleet_files_yaml(mk_request_t *request, void *data)
mk_http_done(request);
}

static void mock_server_registration(mk_request_t *request, void *data)
{
/* Use a local buffer with correct size */
const char *response = "{\"id\":\"test_fleet_id\"}";
size_t response_len = strlen(response); // Ensure size is accurate

mk_http_status(request, 200);
mk_http_header(request, "Content-Type", sizeof("Content-Type") - 1,
"application/json", sizeof("application/json") - 1);
mk_http_send(request, response, response_len, NULL); // Use response_len
mk_http_done(request);
}


static void test_in_fleet_get_calyptia_files() {
char tmp[256] = {0};
struct test_context *t_ctx = init_test_context();
Expand All @@ -183,6 +197,12 @@ static void test_in_fleet_get_calyptia_files() {
ret = mk_vhost_handler(mock_ctx, vid, tmp, mock_server_fleet_files_yaml, NULL);
TEST_CHECK(ret == 0);

ret = mk_vhost_handler(mock_ctx, vid, "/v1/agents", mock_server_registration, NULL);
TEST_CHECK(ret == 0);

ret = mk_vhost_handler(mock_ctx, vid, "/v1/agents/test_fleet_id", mock_server_registration, NULL);
TEST_CHECK(ret == 0);

ret = mk_start(mock_ctx);
TEST_CHECK(ret == 0);

Expand Down Expand Up @@ -234,6 +254,12 @@ static void test_in_fleet_get_calyptia_files() {
TEST_CHECK(tomlRequests == 1);
TEST_CHECK(yamlRequests == 1);

/* Cleanup */
flb_stop(ctx);
flb_destroy(ctx);
mk_stop(mock_ctx);
mk_destroy(mock_ctx);

cleanup_test_context(t_ctx);
}

Expand Down

0 comments on commit 86bf6d4

Please sign in to comment.