def test_print(cartridge_cmd, custom_admin_running_instances, connection_type, tmpdir): project = custom_admin_running_instances['project'] ITERATIONS_NUM = 3 cmd = [ cartridge_cmd, 'admin', 'func_print', '--num', str(ITERATIONS_NUM), ] cmd.extend(get_admin_connection_params(connection_type, project)) rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 iterations_output = [] for i in range(1, ITERATIONS_NUM + 1): iterations_output.extend([ '• Iteration %s (printed)' % i, '• Iteration %s (pushed)' % i, ]) assert get_log_lines(output) == iterations_output + [ '• I am some great result', ]
def test_func_raises_err(cartridge_cmd, custom_admin_running_instances, connection_type, tmpdir): project = custom_admin_running_instances['project'] cmd = [ cartridge_cmd, 'admin', 'func_raises_err', ] cmd.extend(get_admin_connection_params(connection_type, project)) rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 1 assert '⨯ Failed to call "func_raises_err":' in output assert 'Some horrible error raised' in output
def test_func_rets_str(cartridge_cmd, custom_admin_running_instances, connection_type, tmpdir): project = custom_admin_running_instances['project'] cmd = [ cartridge_cmd, 'admin', 'func_rets_str', ] cmd.extend(get_admin_connection_params(connection_type, project)) rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ '• func_rets_str was called', ]
def test_func_rets_non_str(cartridge_cmd, custom_admin_running_instances, connection_type, tmpdir): project = custom_admin_running_instances['project'] cmd = [ cartridge_cmd, 'admin', 'func_rets_non_str', ] cmd.extend(get_admin_connection_params(connection_type, project)) rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ '• 666', '• Admin function should return string or string array value', ]
def test_list(cartridge_cmd, custom_admin_running_instances, connection_type, tmpdir): project = custom_admin_running_instances['project'] cmd = [cartridge_cmd, 'admin', '--list'] cmd.extend(get_admin_connection_params(connection_type, project)) rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ '• Available admin functions:', 'echo_user echo_user usage', 'func.long.name func_long_name usage', 'func_conflicting func_conflicting usage', 'func_long_arg func_long_arg usage', 'func_no_args func_no_args usage', 'func_print func_print usage', 'func_raises_err func_raises_err usage', 'func_rets_err func_rets_err usage', 'func_rets_non_str func_rets_non_str usage', 'func_rets_str func_rets_str usage', ]
def test_help_many_args(cartridge_cmd, custom_admin_running_instances, connection_type, tmpdir): project = custom_admin_running_instances['project'] cmd = [ cartridge_cmd, 'admin', 'echo_user', '--help', ] cmd.extend(get_admin_connection_params(connection_type, project)) rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ '• Admin function "echo_user" usage:', 'echo_user usage', 'Args:', '--age number age usage', '--loves-cakes boolean loves_cakes usage', '--username string username usage', ]
def test_default_admin_func(cartridge_cmd, default_admin_running_instances, connection_type, tmpdir): project = default_admin_running_instances['project'] run_dir = project.get_run_dir() # list cmd = [cartridge_cmd, 'admin', '--list'] cmd.extend(get_admin_connection_params(connection_type, project)) rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ '• Available admin functions:', 'probe Probe instance', ] # help cmd = [ cartridge_cmd, 'admin', '--name', project.name, '--run-dir', run_dir, '--help', 'probe', ] rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ '• Admin function "probe" usage:', 'Probe instance', 'Args:', '--uri string Instance URI', ] # call w/ --uri localhost:3301 - OK cmd = [ cartridge_cmd, 'admin', '--name', project.name, '--run-dir', run_dir, 'probe', '--uri', 'localhost:3301', ] rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ '• Probe "localhost:3301": OK', ] # call w/ --uri localhost:3311 - fail cmd = [ cartridge_cmd, 'admin', '--name', project.name, '--run-dir', run_dir, 'probe', '--uri', 'localhost:3311', ] rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 1 assert get_log_lines(output) == [ '⨯ Failed to call "probe": Probe "localhost:3311" failed: no response', ]
def test_call_many_args(cartridge_cmd, custom_admin_running_instances, connection_type, tmpdir): project = custom_admin_running_instances['project'] base_cmd = [ cartridge_cmd, 'admin', 'echo_user', ] base_cmd.extend(get_admin_connection_params(connection_type, project)) # all args cmd = base_cmd + [ '--username', 'Elizabeth', '--age', '24', '--loves-cakes', ] rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ '• Hi, Elizabeth!', '• You are 24 years old', '• I know that you like cakes!', ] # age is float cmd = base_cmd + [ '--username', 'Elizabeth', '--age', '23.5', '--loves-cakes', ] rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ '• Hi, Elizabeth!', '• You are 23.5 years old', '• I know that you like cakes!', ] # age missed # check that default number flag value (0) isn't passed cmd = base_cmd + [ '--username', 'Elizabeth', '--loves-cakes', ] rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ "• Hi, Elizabeth!", "• I don't know your age", "• I know that you like cakes!", ] # bool flag is false cmd = base_cmd + [ '--username', 'Elizabeth', '--loves-cakes=false', ] rc, output = run_command_and_get_output(cmd, cwd=tmpdir) assert rc == 0 assert get_log_lines(output) == [ "• Hi, Elizabeth!", "• I don't know your age", "• How can you not love cakes?", ]