diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 93bed91ef654d2760a5eabbf30b08e3428c3cc59..3d35b9724dbd7c8d7d4492c7996ec2dca421c44a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,9 @@ include: - project: shore/ci-templates file: templates/gitlab-release.yml +variables: + GIT_SUBMODULE_STRATEGY: recursive + build-wheel: extends: .python3-build script: diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..47741028726c137743c6bee7c69bcd224b01de60 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tests/bats_helpers/bats-assert"] + path = tests/bats_helpers/bats-assert + url = https://github.com/bats-core/bats-assert.git diff --git a/tests/bats_helpers/bats-assert b/tests/bats_helpers/bats-assert new file mode 160000 index 0000000000000000000000000000000000000000..e0de84e9c011223e7f88b7ccf1c929f4327097ba --- /dev/null +++ b/tests/bats_helpers/bats-assert @@ -0,0 +1 @@ +Subproject commit e0de84e9c011223e7f88b7ccf1c929f4327097ba diff --git a/tests/mnpw.bats b/tests/mnpw.bats deleted file mode 100644 index 731e64c3c07122315e264cc91f7865c36126f2bd..0000000000000000000000000000000000000000 --- a/tests/mnpw.bats +++ /dev/null @@ -1,49 +0,0 @@ -# vim:ft=bash - -@test "help" { - run dist/mnpw --help - [ "$status" -eq 0 ] -} - -@test "version" { - run dist/mnpw --version - [ "$status" -eq 0 ] -} - -@test "true" { - run dist/mnpw true - [ "$status" -eq 0 ] -} - -@test "command not found" { - run dist/mnpw --dry-run /foobar - [ "$status" -eq 2 ] -} - -@test "warning" { - run dist/mnpw --dry-run -- /bin/sh -c 'exit 1' -} - -@test "critical" { - run dist/mnpw --dry-run -- /bin/sh -c 'exit 2' -} - -@test "unknown" { - run dist/mnpw --dry-run -- /bin/sh -c 'exit 3' -} - -@test "other" { - run dist/mnpw --dry-run -- /bin/sh -c 'exit 4' -} - -@test "timeout" { - run dist/mnpw --dry-run --timeout 2 -- /bin/sh -c 'sleep 6' - [ "$status" -eq 2 ] -} - -@test "quiet" { - run dist/mnpw --dry-run --quiet false - [ "$output" = '' ] - run dist/mnpw --dry-run --quiet foobar - [ "$output" != '' ] -} diff --git a/tests/test_mnpw.bats b/tests/test_mnpw.bats new file mode 100644 index 0000000000000000000000000000000000000000..f5c028f6a4742fbfbc0f16a9664a7430a13576e9 --- /dev/null +++ b/tests/test_mnpw.bats @@ -0,0 +1,61 @@ +# vim:ft=bash + +setup () { + load "bats_helpers/bats-assert/load" + PATH="$BATS_TEST_DIRNAME/../dist:$PATH" +} + +@test "help" { + run mnpw --help + assert_success + assert_output --partial 'usage:' +} + +@test "version" { + run mnpw --version + assert_success + assert_output --partial 'mnpw version' +} + +@test "silent and verbose" { + run mnpw --silent --verbose /bin/true + assert_failure 2 +} + +@test "true" { + run mnpw /bin/true + assert_success +} + +@test "command not found" { + run mnpw --dry-run /foobar + assert_failure 2 +} + +@test "warning" { + run mnpw --dry-run -- /bin/sh -c 'exit 1' +} + +@test "critical" { + run mnpw --dry-run -- /bin/sh -c 'exit 2' +} + +@test "unknown" { + run mnpw --dry-run -- /bin/sh -c 'exit 3' +} + +@test "invalid return code" { + run mnpw --dry-run -- /bin/sh -c 'exit 4' +} + +@test "timeout" { + run mnpw --dry-run --timeout 2 -- /bin/sh -c 'sleep 6' + assert_failure 2 +} + +@test "quiet" { + run mnpw --dry-run --quiet false + assert_output '' + run mnpw --dry-run --quiet foobar + assert_output +} diff --git a/tests/test_nagios.py b/tests/test_nagios.py index 2483c6e3d5c8356c14a4682812e3f7d3287a493c..4a7e1c58e5540cb7a12cc1c960a3996d05588042 100644 --- a/tests/test_nagios.py +++ b/tests/test_nagios.py @@ -19,6 +19,20 @@ DISK OK - free space: / 3326 MB (56%); | /=2643MB;5948;5958;0;5968 /var/log=818MB;970;975;0;980 """ +# Lifted from the Alignak project: +# https://github.com/Alignak-monitoring/alignak/blob/fcc3d6499478ce67f4b91c694111f45cc8282535/tests/test_perfdata_parsing.py +PERF_DATA_1 = """ramused=90%;85;95;;""" +PERF_DATA_2 = """ramused=1009MB;;;0;1982 """ +PERF_DATA_3 = """memused=1550MB;2973;3964;0;5810""" +PERF_DATA_4 = """swapused=540MB;;;; """ +PERF_DATA_5 = """memused=90%""" +PERF_DATA_6 = """'Physical Memory Used'=12085620736Bytes; """ +PERF_DATA_7 = """Physical Memory Utilisation'=94%;80;90;""" +PERF_DATA_8 = """'C: used'=13.06452GB;22.28832;25.2601;0;29.71777 """ +PERF_DATA_9 = """'C: used %'=44%;75;85;0;100""" +PERF_DATA_10 = """time_offset-192.168.0.1=-7.22636468709e-05s;1;2;0;;""" +PERF_DATA_11 = """àéèï-192.168.0.1=-7.22636468709e-05s;1;2;0;;""" + @pytest.mark.parametrize( "command,args,exit_code",