From 5196e3367b316faeb8b6b7d5204333e55e4ea61d Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Mon, 25 May 2020 03:10:39 -0700 Subject: Add tests for 'trigger_custom' subcommand Change-Id: I7a2811618adcaaa698a702d264ef2a93bc899704 Issue-ID: INT-1577 Signed-off-by: Bartek Grzybowski --- test/mocks/mass-pnf-sim/conftest.py | 4 ++++ test/mocks/mass-pnf-sim/test_cli.py | 12 ++++++++++++ test/mocks/mass-pnf-sim/test_lifecycle.py | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/test/mocks/mass-pnf-sim/conftest.py b/test/mocks/mass-pnf-sim/conftest.py index b1f688d17..b5502f304 100644 --- a/test/mocks/mass-pnf-sim/conftest.py +++ b/test/mocks/mass-pnf-sim/conftest.py @@ -28,3 +28,7 @@ def args_status(parser): @pytest.fixture(scope="module") def args_trigger(parser): return parser.parse_args(['trigger']) + +@pytest.fixture(scope="module") +def args_trigger_custom(parser): + return parser.parse_args(['trigger_custom', '--triggerstart', '0', '--triggerend', str(SIM_INSTANCES-1)]) diff --git a/test/mocks/mass-pnf-sim/test_cli.py b/test/mocks/mass-pnf-sim/test_cli.py index bc4d276ed..f574a725d 100644 --- a/test/mocks/mass-pnf-sim/test_cli.py +++ b/test/mocks/mass-pnf-sim/test_cli.py @@ -1,4 +1,6 @@ import pytest +from MassPnfSim import MassPnfSim +from test_settings import SIM_INSTANCES @pytest.mark.parametrize(('expect_string, cli_opts'), [ ("bootstrap: error: the following arguments are required: --urlves, --ipfileserver, --typefileserver, --ipstart", @@ -19,6 +21,16 @@ def test_subcommands(parser, capsys, expect_string, cli_opts): pass assert expect_string in capsys.readouterr().err +def test_validate_trigger_custom(parser, caplog): + args = parser.parse_args(['trigger_custom', '--triggerstart', '0', + '--triggerend', str(SIM_INSTANCES)]) + try: + MassPnfSim(args).trigger_custom() + except SystemExit as e: + assert e.code == 1 + assert "--triggerend value greater than existing instance count" in caplog.text + caplog.clear() + @pytest.mark.parametrize(("subcommand"), [ 'bootstrap', 'start', diff --git a/test/mocks/mass-pnf-sim/test_lifecycle.py b/test/mocks/mass-pnf-sim/test_lifecycle.py index 5eaa40946..1ae696c84 100644 --- a/test/mocks/mass-pnf-sim/test_lifecycle.py +++ b/test/mocks/mass-pnf-sim/test_lifecycle.py @@ -94,3 +94,14 @@ def test_trigger_idempotence(args_trigger, capfd): msg = capfd.readouterr() assert "Cannot start simulator since it's already running" in msg.out assert 'Simulator started' not in msg.out + +def test_trigger_custom(args_trigger_custom, caplog, capfd): + MassPnfSim(args_trigger_custom).trigger_custom() + msg = capfd.readouterr() + for instance in range(SIM_INSTANCES): + instance_ip_offset = instance * 16 + ip_offset = 2 + assert f'Triggering pnf-sim-lw-{instance} instance:' in caplog.text + assert f'PNF-Sim IP: {str(ip_address(IPSTART) + ip_offset + instance_ip_offset)}' in msg.out + assert 'Simulator started' not in msg.out + assert "Cannot start simulator since it's already running" in msg.out -- cgit 1.2.3-korg