Skip to content

Commit 682776d

Browse files
committed
tests: add port configuration tests for kinesis_streams output plugin
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]>
1 parent d383b47 commit 682776d

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

tests/runtime/out_kinesis.c

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,110 @@ void flb_test_firehose_nonsense_error(void)
188188
unsetenv("TEST_PUT_RECORDS_ERROR");
189189
}
190190

191+
void flb_test_kinesis_default_port(void)
192+
{
193+
int ret;
194+
flb_ctx_t *ctx;
195+
int in_ffd;
196+
int out_ffd;
197+
struct flb_output_instance *out;
198+
199+
/* mocks calls- signals that we are in test mode */
200+
setenv("FLB_KINESIS_PLUGIN_UNDER_TEST", "true", 1);
201+
202+
ctx = flb_create();
203+
TEST_CHECK(ctx != NULL);
204+
205+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
206+
TEST_CHECK(in_ffd >= 0);
207+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
208+
209+
out_ffd = flb_output(ctx, (char *) "kinesis_streams", NULL);
210+
TEST_CHECK(out_ffd >= 0);
211+
flb_output_set(ctx, out_ffd, "match", "*", NULL);
212+
flb_output_set(ctx, out_ffd, "region", "us-west-2", NULL);
213+
flb_output_set(ctx, out_ffd, "stream", "fluent", NULL);
214+
flb_output_set(ctx, out_ffd, "time_key", "time", NULL);
215+
216+
/* Start the engine */
217+
ret = flb_start(ctx);
218+
TEST_CHECK(ret == 0);
219+
220+
/* Get the output instance */
221+
out = flb_output_get_instance(ctx->config, out_ffd);
222+
TEST_CHECK(out != NULL);
223+
224+
/* Check if the port is set to the default value */
225+
const char* port = flb_output_get_property("port", out);
226+
TEST_CHECK(port == NULL || strcmp(port, "443") == 0);
227+
TEST_MSG("Default port should be 443 or not set, but got %s", port ? port : "NULL");
228+
229+
flb_stop(ctx);
230+
flb_destroy(ctx);
231+
}
232+
233+
234+
void flb_test_kinesis_custom_port(void)
235+
{
236+
int ret;
237+
flb_ctx_t *ctx;
238+
int in_ffd;
239+
int out_ffd;
240+
241+
/* mocks calls- signals that we are in test mode */
242+
setenv("FLB_KINESIS_PLUGIN_UNDER_TEST", "true", 1);
243+
244+
ctx = flb_create();
245+
246+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
247+
TEST_CHECK(in_ffd >= 0);
248+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
249+
250+
out_ffd = flb_output(ctx, (char *) "kinesis_streams", NULL);
251+
TEST_CHECK(out_ffd >= 0);
252+
flb_output_set(ctx, out_ffd, "match", "*", NULL);
253+
flb_output_set(ctx, out_ffd, "region", "us-west-2", NULL);
254+
flb_output_set(ctx, out_ffd, "stream", "fluent", NULL);
255+
flb_output_set(ctx, out_ffd, "time_key", "time", NULL);
256+
flb_output_set(ctx, out_ffd, "port", "8443", NULL);
257+
flb_output_set(ctx, out_ffd, "Retry_Limit", "1", NULL);
258+
259+
ret = flb_start(ctx);
260+
TEST_CHECK(ret == 0);
261+
262+
flb_stop(ctx);
263+
flb_destroy(ctx);
264+
}
265+
266+
void flb_test_kinesis_invalid_port(void)
267+
{
268+
int ret;
269+
flb_ctx_t *ctx;
270+
int in_ffd;
271+
int out_ffd;
272+
273+
/* mocks calls- signals that we are in test mode */
274+
setenv("FLB_KINESIS_PLUGIN_UNDER_TEST", "true", 1);
275+
276+
ctx = flb_create();
277+
278+
in_ffd = flb_input(ctx, (char *) "lib", NULL);
279+
TEST_CHECK(in_ffd >= 0);
280+
flb_input_set(ctx, in_ffd, "tag", "test", NULL);
281+
282+
out_ffd = flb_output(ctx, (char *) "kinesis_streams", NULL);
283+
TEST_CHECK(out_ffd >= 0);
284+
flb_output_set(ctx, out_ffd, "match", "*", NULL);
285+
flb_output_set(ctx, out_ffd, "region", "us-west-2", NULL);
286+
flb_output_set(ctx, out_ffd, "stream", "fluent", NULL);
287+
flb_output_set(ctx, out_ffd, "port", "99999", NULL); // Invalid port
288+
289+
ret = flb_start(ctx);
290+
TEST_CHECK(ret != 0); // Expect failure
291+
292+
flb_stop(ctx);
293+
flb_destroy(ctx);
294+
}
191295

192296
/* Test list */
193297
TEST_LIST = {
@@ -196,5 +300,8 @@ TEST_LIST = {
196300
{"throughput_error", flb_test_firehose_throughput_error },
197301
{"unknown_error", flb_test_firehose_error_unknown },
198302
{"nonsense_error", flb_test_firehose_nonsense_error },
303+
{"default_port", flb_test_kinesis_default_port },
304+
{"custom_port", flb_test_kinesis_custom_port },
305+
{"invalid_port", flb_test_kinesis_invalid_port },
199306
{NULL, NULL}
200307
};

0 commit comments

Comments
 (0)