@@ -723,6 +723,62 @@ def test_process_scpv2(self):
723723 r'\{(' + inspector + r',' + finished + r'|' + finished + r',' + inspector + r')\}' )
724724
725725 self .assertEqual (command .protocol_version , 2 )
726+
727+ # 5. Different scenarios with allow_empty_input flag, default is True
728+ # Test preparation
729+ dispatch_dir = os .path .join (basedir , 'recordings' , 'scpv2' , 'Splunk-6.3' , 'countmatches.dispatch_dir' )
730+ logging_configuration = os .path .join (basedir , 'apps' , 'app_with_logging_configuration' , 'logging.conf' )
731+ logging_level = 'ERROR'
732+ record = False
733+ show_configuration = True
734+
735+ getinfo_metadata = metadata .format (
736+ dispatch_dir = encode_string (dispatch_dir ),
737+ logging_configuration = encode_string (logging_configuration )[1 :- 1 ],
738+ logging_level = logging_level ,
739+ record = ('true' if record is True else 'false' ),
740+ show_configuration = ('true' if show_configuration is True else 'false' ))
741+
742+ execute_metadata = '{"action":"execute","finished":true}'
743+ command = TestCommand ()
744+ result = BytesIO ()
745+ argv = ['some-external-search-command.py' ]
746+
747+ # Scenario a) Empty body & allow_empty_input=False ==> Assert Error
748+
749+ execute_body = '' # Empty body
750+ input_file = build_command_input (getinfo_metadata , execute_metadata , execute_body )
751+ try :
752+ command .process (argv , input_file , ofile = result , allow_empty_input = False ) # allow_empty_input=False
753+ except SystemExit as error :
754+ self .assertNotEqual (0 , error .code )
755+ self .assertTrue (result .getvalue ().decode ("UTF-8" ).__contains__ ("No records found to process. Set "
756+ "allow_empty_input=True in dispatch "
757+ "function to move forward with empty "
758+ "records." ))
759+ else :
760+ self .fail ('Expected SystemExit, not a return from TestCommand.process: {}\n ' .format (
761+ result .getvalue ().decode ('utf-8' )))
762+
763+ # Scenario b) Empty body & allow_empty_input=True ==> Assert Success
764+
765+ execute_body = '' # Empty body
766+ input_file = build_command_input (getinfo_metadata , execute_metadata , execute_body )
767+ result = BytesIO ()
768+
769+ try :
770+ command .process (argv , input_file , ofile = result ) # By default allow_empty_input=True
771+ except SystemExit as error :
772+ self .fail ('Unexpected exception: {}: {}' .format (type (error ).__name__ , error ))
773+
774+ expected = (
775+ 'chunked 1.0,68,0\n '
776+ '{"inspector":{"messages":[["INFO","test command configuration: "]]}}\n '
777+ 'chunked 1.0,17,0\n '
778+ '{"finished":true}'
779+ )
780+
781+ self .assertEquals (result .getvalue ().decode ("UTF-8" ), expected )
726782 return
727783
728784 _package_directory = os .path .dirname (os .path .abspath (__file__ ))
0 commit comments