Commit d3ab0120 authored by nimrod's avatar nimrod
Browse files

Testing the CLI.

- Test the CLI using Bats. A few test, more to do.
- Found small issues and fixed them!
- Add to CI, remove the job to check the executable runs (covered by
  Bats).
- Run on host01, should be faster to download the binary.
parent 4f1a6a6c
Loading
Loading
Loading
Loading
Loading
+24 −10
Original line number Diff line number Diff line
@@ -32,16 +32,6 @@ install-wheel:
    - mnpw --help
    - mnpw --version

run-executable:
  image: registry.hub.docker.com/library/ubuntu:bionic
  stage: test
  script:
    - dist/mnpw --help
    - dist/mnpw --version
  needs:
    - job: build-executable
      artifacts: true

pytest:
  extends: .python3
  stage: test
@@ -54,3 +44,27 @@ pytest:
      junit: report.xml
  # We don't any artifacts and don't want to wait for the download to finish.
  needs: []

bats:
  image: docker.io/library/debian:bullseye-slim
  stage: test
  tags: [host01.shore.co.il]
  before_script:
    - apt-get update
    - apt-get install -y --no-install-recommends bats ca-certificates curl git
    - >-
      curl
      --location
      https://github.com/cloudbees-oss/juxr/releases/download/0.1.22/juxr-x86_64-unknown-linux-gnu.tar.gz
      |
      tar -zxC /usr/local/bin/
  script:
    - bats tests/ | tee report.tap
  after_script:
    - juxr tap --name bats --output report/ -- cat report.tap
  artifacts:
    reports:
      junit: report/*.xml
  needs:
    - job: build-executable
      artifacts: true
+3 −3
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ def main():
    parser.add_argument(
        "-q",
        "--quiet",
        "--sileent",
        "--silent",
        help="No output, except for errors.",
        action="store_true",
    )
@@ -85,15 +85,15 @@ def main():
    try:
        check.run(args.timeout)
    except Exception as ex:  # pylint: disable=broad-except
        parser.error(str(ex))
        if args.errors:
            notify(f"")
        parser.error(str(ex))

    if check.ExitCode == nagios.NagiosCode.OK:
        logging.info("Check status is OK.")
    elif check.ExitCode == nagios.NagiosCode.WARNING:
        logging.info("Check status is WARNING.")
        if args.warning:
        if args.warn:
            notify(f"")
    elif check.ExitCode == nagios.NagiosCode.CRITICAL:
        logging.info("Check status is CRITICAL.")

tests/mnpw.bats

0 → 100644
+49 −0
Original line number Diff line number Diff line
# 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" != '' ]
}