@@ -347,6 +347,37 @@ int flb_input_set_processor(flb_ctx_t *ctx, int ffd, struct flb_processor *proc)
347347 return 0 ;
348348}
349349
350+ int flb_output_set_http_test (flb_ctx_t * ctx , int ffd , char * test_name ,
351+ void (* out_response ) (void * , int , int , void * , size_t , void * ),
352+ void * out_callback_data )
353+ {
354+ struct flb_output_instance * o_ins ;
355+
356+ o_ins = out_instance_get (ctx , ffd );
357+ if (!o_ins ) {
358+ return -1 ;
359+ }
360+
361+ /*
362+ * Enabling a test, set the output instance in 'test' mode, so no real
363+ * flush callback is invoked, only the desired implemented test.
364+ */
365+
366+ /* Response test */
367+ if (strcmp (test_name , "response" ) == 0 ) {
368+ o_ins -> test_mode = FLB_TRUE ;
369+ o_ins -> test_response .rt_ctx = ctx ;
370+ o_ins -> test_response .rt_ffd = ffd ;
371+ o_ins -> test_response .rt_out_response = out_response ;
372+ o_ins -> test_response .rt_data = out_callback_data ;
373+ }
374+ else {
375+ return -1 ;
376+ }
377+
378+ return 0 ;
379+ }
380+
350381static inline int flb_config_map_property_check (char * plugin_name , struct mk_list * config_map , char * key , char * val )
351382{
352383 struct flb_kv * kv ;
@@ -638,6 +669,41 @@ int flb_lib_free(void* data)
638669}
639670
640671
672+ static int flb_output_run_response (flb_ctx_t * ctx , struct flb_output_instance * o_ins ,
673+ int status , const void * data , size_t len )
674+ {
675+ int ret ;
676+ void * out_buf = NULL ;
677+ size_t out_size = 0 ;
678+ struct flb_test_out_response * resp ;
679+
680+ if (!o_ins ) {
681+ return -1 ;
682+ }
683+
684+ resp = & o_ins -> test_response ;
685+
686+ /* Invoke the input plugin formatter test callback */
687+ ret = resp -> callback (ctx -> config ,
688+ o_ins -> context ,
689+ status , data , len ,
690+ & out_buf , & out_size );
691+
692+ /* Call the runtime test callback checker */
693+ if (resp -> rt_out_response ) {
694+ resp -> rt_out_response (resp -> rt_ctx ,
695+ resp -> rt_ffd ,
696+ ret ,
697+ out_buf , out_size ,
698+ resp -> rt_data );
699+ }
700+ else {
701+ flb_free (out_buf );
702+ }
703+
704+ return 0 ;
705+ }
706+
641707/* Push some data into the Engine */
642708int flb_lib_push (flb_ctx_t * ctx , int ffd , const void * data , size_t len )
643709{
@@ -662,6 +728,29 @@ int flb_lib_push(flb_ctx_t *ctx, int ffd, const void *data, size_t len)
662728 return ret ;
663729}
664730
731+ /* Emulate some data from the response */
732+ int flb_lib_response (flb_ctx_t * ctx , int ffd , int status , const void * data , size_t len )
733+ {
734+ int ret ;
735+ struct flb_output_instance * o_ins ;
736+
737+ if (ctx -> status == FLB_LIB_NONE || ctx -> status == FLB_LIB_ERROR ) {
738+ flb_error ("[lib] cannot push data, engine is not running" );
739+ return -1 ;
740+ }
741+
742+ o_ins = out_instance_get (ctx , ffd );
743+ if (!o_ins ) {
744+ return -1 ;
745+ }
746+
747+ /* If input's test_formatter is registered, priorize to run it. */
748+ if (o_ins -> test_response .callback != NULL ) {
749+ ret = flb_output_run_response (ctx , o_ins , status , data , len );
750+ }
751+ return ret ;
752+ }
753+
665754static void flb_lib_worker (void * data )
666755{
667756 int ret ;
0 commit comments