From c92ff6266b18a9655edef231391739f0479dfb3a Mon Sep 17 00:00:00 2001 From: "Sergey V. Lobanov" Date: Sun, 4 Sep 2022 18:49:42 +0300 Subject: add tests and ci workflow for running tests This commit adds tests (using python3 pytest framework): 1. Test basic accel-cmd commands (show version, show stat, etc) 2. Test ipoe shared session up (dhcpv4) without radius 3. Test pppoe discovery (without PADO delay) 4. Test pppoe discovery (without PADO delay) 5. Test pppoe session up (ipv4) without radius 6. Test vlan creation using vlan-mon (pppoe) These tests require external utils. Please read tests/README.md how to setup environment, how to run the tests and how to generate coverage report Also, run-tests.yml contains step-by-step instruction how to run the tests Signed-off-by: Sergey V. Lobanov --- tests/accel-cmd/test_cmd_basic.py | 26 +++++++++++++++++ tests/accel-cmd/test_real_commands.py | 53 +++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 tests/accel-cmd/test_cmd_basic.py create mode 100644 tests/accel-cmd/test_real_commands.py (limited to 'tests/accel-cmd') diff --git a/tests/accel-cmd/test_cmd_basic.py b/tests/accel-cmd/test_cmd_basic.py new file mode 100644 index 0000000..c6cdc7a --- /dev/null +++ b/tests/accel-cmd/test_cmd_basic.py @@ -0,0 +1,26 @@ +import pytest +from common import process + + +def test_accel_cmd_version(accel_cmd): + (exit, out, err) = process.run([accel_cmd, "--version"]) + + # test that accel-cmd --version exits with code 0, prints + # nothing to stdout and prints to stdout + assert exit == 0 and err == "" and "accel-cmd " in out and len(out.split(" ")) == 2 + + +def test_accel_cmd_non_existent_host(accel_cmd): + (exit, out, err) = process.run([accel_cmd, "-Hnon-existent-host", "--verbose"]) + + # test that accel-cmd (tried to connecto to non-existent host) exits with code != 0, + # prints nothing to stdout and prints an error to stderr + assert exit != 0 and out == "" and err != "" + + +def test_accel_cmd_mcast_host(accel_cmd): + (exit, out, err) = process.run([accel_cmd, "-H225.0.0.1"]) + + # test that accel-cmd (tried to connecto to mcast host) exits with code != 0, + # prints nothing to stdout and prints an error to stderr + assert exit != 0 and out == "" and err != "" diff --git a/tests/accel-cmd/test_real_commands.py b/tests/accel-cmd/test_real_commands.py new file mode 100644 index 0000000..1758b4e --- /dev/null +++ b/tests/accel-cmd/test_real_commands.py @@ -0,0 +1,53 @@ +import pytest +from common import process + + +@pytest.fixture() +def accel_pppd_config(): + return """ + [modules] + + [log] + log-debug=/dev/stdout + level=5 + + [cli] + tcp=127.0.0.1:2001 + """ + + +# test accel-cmd command with started accel-pppd +def test_accel_cmd_commands(accel_pppd_instance, accel_cmd): + + # test that accel-pppd started successfully + assert accel_pppd_instance + + (exit_sh_stat, out_sh_stat, err_sh_stat) = process.run([accel_cmd, "show stat"]) + + # test that 'show stat' has no errors and contains 'uptime' + assert ( + exit_sh_stat == 0 + and len(out_sh_stat) > 0 + and err_sh_stat == "" + and "uptime" in out_sh_stat + ) + + (exit_sh_ses, out_sh_ses, err_sh_ses) = process.run( + [accel_cmd, "show sessions sid,uptime"] + ) + # test that 'show sessions' has no errors and contains 'sid' + assert ( + exit_sh_ses == 0 + and len(out_sh_ses) > 0 + and err_sh_ses == "" + and "sid" in out_sh_ses + ) + + (exit_help, out_help, err_help) = process.run([accel_cmd, "help"]) + # test that 'help' has no errors and contains 'show stat' + assert ( + exit_help == 0 + and len(out_help) > 0 + and err_help == "" + and "show stat" in out_help + ) -- cgit v1.2.3