Skip to content

Commit

Permalink
Improve Coverage & Add Tests (#29)
Browse files Browse the repository at this point in the history
* Improve Coverage

* Adding Actual Unit Test with basic test
  • Loading branch information
smashedr authored Aug 30, 2023
1 parent dc8f8ca commit 18aa051
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
34 changes: 26 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ on:
workflow_dispatch:
inputs:
host:
description: "IP Address of Host to Test"
description: "Host to Test"
type: string
required: false
default: "1.1.1.1"
default: "one.one.one.one"
ipv6:
description: "IPv6 to Test"
type: string
required: false
default: "2606:4700:4700::1111"
critical:
description: "Critical Level to Test"
type: string
Expand All @@ -25,14 +30,16 @@ on:

env:
COVERALLS_VERSION: "3.11"
TEST_HOST: ${{ github.event.inputs.host || '1.1.1.1' }}
TEST_HOST: ${{ github.event.inputs.host || 'one.one.one.one' }}
TEST_IPV4: "1.1.1.1"
TEST_IPV6: ${{ github.event.inputs.ipv6 || '2606:4700:4700::1111' }}
CRITICAL: ${{ github.event.inputs.critical || '99' }}
WARNING: ${{ github.event.inputs.warning || '99' }}

jobs:
test:
name: Test
timeout-minutes: 5
timeout-minutes: 10
if: ${{ !contains(github.event.head_commit.message, '#noci') }}
strategy:
matrix:
Expand Down Expand Up @@ -65,16 +72,27 @@ jobs:
- name: "Dependencies ${{ matrix.version }}"
run: |
python -m pip install --upgrade pip
pip install flake8 coverage
pip install flake8 coverage pytest
- name: "Lint ${{ matrix.version }}"
run: |
flake8 check_rbl.py
- name: "Test ${{ matrix.version }}"
- name: "Pytest ${{ matrix.version }}"
run: |
pytest
- name: "Coverage ${{ matrix.version }}"
if: ${{ matrix.version == env.COVERALLS_VERSION }}
run: |
coverage run check_rbl.py -w $WARNING -c $CRITICAL -a $TEST_HOST
coverage report
coverage run check_rbl.py ||:
coverage run -a check_rbl.py -w $WARNING ||:
coverage run -a check_rbl.py -a $TEST_IPV4 -h $TEST_HOST ||:
coverage run -a check_rbl.py --ipv4 $TEST_IPV4 --ipv6 $TEST_IPV6 ||:
coverage run -a check_rbl.py -h invalid.com ||:
coverage run -a check_rbl.py -d -w $WARNING -c $CRITICAL -h $TEST_HOST
coverage run -a check_rbl.py -d -w $WARNING -c $CRITICAL -a $TEST_IPV6
coverage report -m
- name: "Coveralls"
if: ${{ matrix.version == env.COVERALLS_VERSION }}
Expand Down
56 changes: 56 additions & 0 deletions test_check_rbl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import subprocess

status = {'OK': 0, 'WARNING': 1, 'CRITICAL': 2, 'UNKNOWN': 3}
test_host = 'one.one.one.one'
test_ipv4 = '1.1.1.1'
test_ipv6 = '2606:4700:4700::1111'
crit = 99
warn = 99


def test_no_options():
command = 'python check_rbl.py'
result = subprocess.run(command.split())
assert result.returncode == status['UNKNOWN']


def test_len_options():
command = 'python check_rbl.py -w 99'
result = subprocess.run(command.split())
assert result.returncode == status['UNKNOWN']


def test_host_and_ip():
command = f'python check_rbl.py -a {test_ipv4} -h {test_host}'
result = subprocess.run(command.split())
assert result.returncode == status['UNKNOWN']


def test_ipv4_and_ipv6():
command = f'python check_rbl.py --ipv4 {test_ipv4} --ipv6 {test_ipv6}'
result = subprocess.run(command.split())
assert result.returncode == status['UNKNOWN']


def test_error_resolving():
command = f'python check_rbl.py -h invalid.com'
result = subprocess.run(command.split())
assert result.returncode == status['UNKNOWN']


def test_full_run_host():
command = f'python check_rbl.py -d -w {warn} -c {crit} -h {test_host}'
result = subprocess.run(command.split())
assert result.returncode == status['OK']


def test_full_run_ipv4():
command = f'python check_rbl.py -d -w {warn} -c {crit} -a {test_ipv4}'
result = subprocess.run(command.split())
assert result.returncode == status['OK']


def test_full_run_ipv6():
command = f'python check_rbl.py -d -w {warn} -c {crit} -a {test_ipv6}'
result = subprocess.run(command.split())
assert result.returncode == status['OK']

0 comments on commit 18aa051

Please sign in to comment.