blob: 70c9b6c4f0b47b36764acaf3167cd1a80b6636fa [file] [log] [blame]
Bartek Grzybowski896cc8b2020-05-20 06:34:27 -07001import pytest
Bartek Grzybowski5196e332020-05-25 03:10:39 -07002from MassPnfSim import MassPnfSim
3from test_settings import SIM_INSTANCES
Bartek Grzybowski896cc8b2020-05-20 06:34:27 -07004
Bartek Grzybowski896cc8b2020-05-20 06:34:27 -07005@pytest.mark.parametrize(('expect_string, cli_opts'), [
Bartek Grzybowskicc01b3a2020-06-16 16:39:44 +02006 ("bootstrap: error: the following arguments are required: --urlves, --ipfileserver, --typefileserver, " +\
7 "--user, --password, --ipstart",
Bartek Grzybowski896cc8b2020-05-20 06:34:27 -07008 ['bootstrap']),
9 ("bootstrap: error: argument --typefileserver: invalid choice: 'dummy' (choose from 'sftp', 'ftps')",
10 ['bootstrap', '--typefileserver', 'dummy']),
11 ("bootstrap: error: argument --urlves: invalid_url is not a valid URL",
12 ['bootstrap', '--urlves', 'invalid_url']),
13 ("bootstrap: error: argument --ipstart: x.x.x.x is not a valid IP address",
14 ['bootstrap', '--ipstart', 'x.x.x.x']),
15 ("trigger_custom: error: the following arguments are required: --triggerstart, --triggerend",
16 ['trigger_custom'])
17 ])
18def test_subcommands(parser, capsys, expect_string, cli_opts):
19 try:
20 parser.parse_args(cli_opts)
21 except SystemExit:
22 pass
23 assert expect_string in capsys.readouterr().err
24
Bartek Grzybowski5196e332020-05-25 03:10:39 -070025def test_validate_trigger_custom(parser, caplog):
26 args = parser.parse_args(['trigger_custom', '--triggerstart', '0',
27 '--triggerend', str(SIM_INSTANCES)])
28 try:
29 MassPnfSim(args).trigger_custom()
30 except SystemExit as e:
31 assert e.code == 1
32 assert "--triggerend value greater than existing instance count" in caplog.text
33 caplog.clear()
34
Bartek Grzybowski896cc8b2020-05-20 06:34:27 -070035@pytest.mark.parametrize(("subcommand"), [
36 'bootstrap',
37 'start',
38 'stop',
39 'trigger',
Bartek Grzybowskia3737ae2020-06-05 15:07:56 +020040 'status',
41 'stop_simulator'
Bartek Grzybowski896cc8b2020-05-20 06:34:27 -070042 ])
43def test_count_option(parser, capsys, subcommand):
Bartek Grzybowskidf5004b2020-06-05 11:32:44 +020044 '''Test case where no arg passed to '--count' opt'''
Bartek Grzybowski896cc8b2020-05-20 06:34:27 -070045 try:
46 parser.parse_args([subcommand, '--count'])
47 except SystemExit:
48 pass
49 assert f"{subcommand}: error: argument --count: expected one argument" in capsys.readouterr().err
50
Bartek Grzybowskidf5004b2020-06-05 11:32:44 +020051@pytest.mark.parametrize(("subcommand"), [
52 'start',
53 'stop',
54 'trigger',
Bartek Grzybowskia3737ae2020-06-05 15:07:56 +020055 'status',
56 'stop_simulator'
Bartek Grzybowskidf5004b2020-06-05 11:32:44 +020057 ])
58def test_count_option_bad_value(parser, caplog, subcommand):
59 '''Test case where invalid value passed to '--count' opt'''
60 try:
61 args = parser.parse_args([subcommand, '--count', str(SIM_INSTANCES + 1)])
62 m = getattr(MassPnfSim(args), subcommand)
63 m()
64 except SystemExit:
65 pass
66 assert '--count value greater that existing instance count' in caplog.text
67 caplog.clear()
68
Bartek Grzybowski896cc8b2020-05-20 06:34:27 -070069def test_empty(parser, capsys):
70 try:
71 parser.parse_args([])
72 except SystemExit:
73 pass
74 assert '' is capsys.readouterr().err
75 assert '' is capsys.readouterr().out