@@ -111,6 +111,26 @@ static void cb_check_format_multiple_records(void *ctx, int ffd,
111111 flb_sds_destroy (res_data );
112112}
113113
114+ static void cb_check_format_partially_succeeded_records (void * ctx , int ffd ,
115+ int res_ret , void * res_data ,
116+ size_t res_size , void * data )
117+ {
118+ char * out_json = res_data ;
119+ char * p1 , * p2 ;
120+
121+ set_output_invoked (1 );
122+
123+ p1 = strstr (out_json , "\"log_text\":\"record one\"" );
124+ if (!TEST_CHECK (p1 != NULL )) {
125+ TEST_MSG ("Expected log_text with specific value not found. Got: %s" , out_json );
126+ }
127+
128+ p2 = strstr (out_json , "\"test\"" );
129+ TEST_CHECK (p2 == NULL );
130+
131+ flb_sds_destroy (res_data );
132+ }
133+
114134void test_format_no_log_key ()
115135{
116136 flb_ctx_t * ctx ;
@@ -261,10 +281,53 @@ void test_format_multiple_records()
261281 flb_destroy (ctx );
262282}
263283
284+ void test_format_partially_suceeded_records ()
285+ {
286+ flb_ctx_t * ctx ;
287+ int in_ffd , out_ffd ;
288+ char record1 [1024 ];
289+ char record2 [1024 ];
290+ time_t now = time (NULL );
291+
292+ ctx = flb_create ();
293+ flb_service_set (ctx , "flush" , "0.2" , "grace" , "1" , "log_level" , "error" , NULL );
294+
295+ in_ffd = flb_input (ctx , (char * ) "lib" , NULL );
296+ flb_input_set (ctx , in_ffd , "tag" , "test" , NULL );
297+
298+ out_ffd = flb_output (ctx , (char * ) "chronicle" , NULL );
299+ flb_output_set (ctx , out_ffd ,
300+ "match" , "test" ,
301+ "customer_id" , "test-customer" ,
302+ "project_id" , "TESTING_FORMAT" ,
303+ "log_key" , "message" ,
304+ "log_type" , "TEST_LOG" ,
305+ NULL );
306+
307+ flb_output_set_test (ctx , out_ffd , "formatter" , cb_check_format_partially_succeeded_records , NULL , NULL );
308+
309+ flb_start (ctx );
310+ clear_output_invoked ();
311+
312+ snprintf (record1 , sizeof (record1 ) - 1 , "[%ld, {\"message\": \"record one\"}]" , (long ) now );
313+ snprintf (record2 , sizeof (record2 ) - 1 , "[%ld, {\"test\": \"record two\"}]" , (long ) now + 1 );
314+
315+ flb_lib_push (ctx , in_ffd , record1 , strlen (record1 ));
316+ flb_lib_push (ctx , in_ffd , record2 , strlen (record2 ));
317+
318+ sleep (1 );
319+
320+ TEST_CHECK (get_output_invoked () == 1 );
321+ flb_stop (ctx );
322+ flb_destroy (ctx );
323+ }
324+
325+
264326TEST_LIST = {
265327 { "format_no_log_key" , test_format_no_log_key },
266328 { "format_with_log_key_found" , test_format_with_log_key_found },
267329 { "format_with_log_key_not_found" , test_format_with_log_key_not_found },
268330 { "format_multiple_records" , test_format_multiple_records },
331+ { "format_partially_suceeded_records" , test_format_partially_suceeded_records },
269332 { NULL , NULL }
270333};
0 commit comments