Skip to content

Commit

Permalink
tests: add port configuration tests for kinesis_streams output plugin
Browse files Browse the repository at this point in the history
This commit introduces three new test cases for the kinesis_streams output plugin:

1. flb_test_kinesis_default_port: Verifies that the plugin works correctly
   with the default port configuration.

2. flb_test_kinesis_custom_port: Ensures that the plugin can be configured
   to use a custom port (8443 in this case) and still function properly.

3. flb_test_kinesis_invalid_port: Checks that the plugin fails to start
   when an invalid port number (99999) is specified.

These tests enhance the coverage of the kinesis_streams plugin by validating
its behavior with different port configurations, including error handling
for invalid inputs.

Signed-off-by: Mikhail [azalio] Petrov <[email protected]>
  • Loading branch information
azalio committed Aug 30, 2024
1 parent f806cce commit 82799d3
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions tests/runtime/out_kinesis.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <fluent-bit.h>
#include "flb_tests_runtime.h"
#include "../../plugins/out_kinesis_streams//kinesis.h"


/* Test data */
#include "data/td/json_td.h" /* JSON_TD */
Expand Down Expand Up @@ -188,6 +190,110 @@ void flb_test_firehose_nonsense_error(void)
unsetenv("TEST_PUT_RECORDS_ERROR");
}

void flb_test_kinesis_default_port(void)
{
int ret;
flb_ctx_t *ctx;
int in_ffd;
int out_ffd;
struct flb_output_instance *out;

/* mocks calls- signals that we are in test mode */
setenv("FLB_KINESIS_PLUGIN_UNDER_TEST", "true", 1);

ctx = flb_create();
TEST_CHECK(ctx != NULL);

in_ffd = flb_input(ctx, (char *) "lib", NULL);
TEST_CHECK(in_ffd >= 0);
flb_input_set(ctx, in_ffd, "tag", "test", NULL);

out_ffd = flb_output(ctx, (char *) "kinesis_streams", NULL);
TEST_CHECK(out_ffd >= 0);
flb_output_set(ctx, out_ffd, "match", "*", NULL);
flb_output_set(ctx, out_ffd, "region", "us-west-2", NULL);
flb_output_set(ctx, out_ffd, "stream", "fluent", NULL);
flb_output_set(ctx, out_ffd, "time_key", "time", NULL);

/* Start the engine */
ret = flb_start(ctx);
TEST_CHECK(ret == 0);

/* Get the output instance */
out = flb_output_get_instance(ctx->config, out_ffd);
TEST_CHECK(out != NULL);

/* Check if the port is set to the default value */
const char* port = flb_output_get_property("port", out);
TEST_CHECK(port == NULL || strcmp(port, "443") == 0);
TEST_MSG("Default port should be 443 or not set, but got %s", port ? port : "NULL");

flb_stop(ctx);
flb_destroy(ctx);
}


void flb_test_kinesis_custom_port(void)
{
int ret;
flb_ctx_t *ctx;
int in_ffd;
int out_ffd;

/* mocks calls- signals that we are in test mode */
setenv("FLB_KINESIS_PLUGIN_UNDER_TEST", "true", 1);

ctx = flb_create();

in_ffd = flb_input(ctx, (char *) "lib", NULL);
TEST_CHECK(in_ffd >= 0);
flb_input_set(ctx, in_ffd, "tag", "test", NULL);

out_ffd = flb_output(ctx, (char *) "kinesis_streams", NULL);
TEST_CHECK(out_ffd >= 0);
flb_output_set(ctx, out_ffd, "match", "*", NULL);
flb_output_set(ctx, out_ffd, "region", "us-west-2", NULL);
flb_output_set(ctx, out_ffd, "stream", "fluent", NULL);
flb_output_set(ctx, out_ffd, "time_key", "time", NULL);
flb_output_set(ctx, out_ffd, "port", "8443", NULL);
flb_output_set(ctx, out_ffd, "Retry_Limit", "1", NULL);

ret = flb_start(ctx);
TEST_CHECK(ret == 0);

flb_stop(ctx);
flb_destroy(ctx);
}

void flb_test_kinesis_invalid_port(void)
{
int ret;
flb_ctx_t *ctx;
int in_ffd;
int out_ffd;

/* mocks calls- signals that we are in test mode */
setenv("FLB_KINESIS_PLUGIN_UNDER_TEST", "true", 1);

ctx = flb_create();

in_ffd = flb_input(ctx, (char *) "lib", NULL);
TEST_CHECK(in_ffd >= 0);
flb_input_set(ctx, in_ffd, "tag", "test", NULL);

out_ffd = flb_output(ctx, (char *) "kinesis_streams", NULL);
TEST_CHECK(out_ffd >= 0);
flb_output_set(ctx, out_ffd, "match", "*", NULL);
flb_output_set(ctx, out_ffd, "region", "us-west-2", NULL);
flb_output_set(ctx, out_ffd, "stream", "fluent", NULL);
flb_output_set(ctx, out_ffd, "port", "99999", NULL); // Invalid port

ret = flb_start(ctx);
TEST_CHECK(ret != 0); // Expect failure

flb_stop(ctx);
flb_destroy(ctx);
}

/* Test list */
TEST_LIST = {
Expand All @@ -196,5 +302,8 @@ TEST_LIST = {
{"throughput_error", flb_test_firehose_throughput_error },
{"unknown_error", flb_test_firehose_error_unknown },
{"nonsense_error", flb_test_firehose_nonsense_error },
{"default_port", flb_test_kinesis_default_port },
{"custom_port", flb_test_kinesis_custom_port },
{"invalid_port", flb_test_kinesis_invalid_port },
{NULL, NULL}
};

0 comments on commit 82799d3

Please sign in to comment.