diff --git a/tests/runtime/out_kinesis.c b/tests/runtime/out_kinesis.c index da3e925a0f8..c8e44a4c874 100644 --- a/tests/runtime/out_kinesis.c +++ b/tests/runtime/out_kinesis.c @@ -188,6 +188,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 = { @@ -196,5 +300,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} };