add unittests

This commit is contained in:
2021-08-30 03:08:26 +02:00
parent 0aec746eb3
commit e3cf03338a
2 changed files with 53 additions and 0 deletions

3
run_tests.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/env bash
pipenv run python -m unittest -bv test_dnsverify

50
test_dnsverify.py Normal file
View File

@@ -0,0 +1,50 @@
#!/bin/env python
'''
Unit tests for dnsverify
'''
import unittest
from dnsverify import do_check
from dnsverify import get_authoritative_ns
from dnsverify import get_domains_from_yaml
from dnsverify import verify_authoritative_ns
from pylint.lint import Run
from pylint.reporters import CollectingReporter
class TestDnsVerify(unittest.TestCase):
def test_do_check(self):
'''
... Test if checks acutally fail when an error occures.
'''
self.assertEqual(do_check(['puzzle.ch'],
['ns1.google.com'],
verbose=False),
False)
def test_get_authoritative_ns(self):
'''
... Test if garbage queries trigger a stack trace.
'''
self.assertEqual(get_authoritative_ns('dinimer.lolwas'), [])
def test_get_domains_from_yaml(self):
'''
... Test wheter missing files generate an empty list.
'''
self.assertEqual(get_domains_from_yaml(["notexist.yaml"]), [])
def test_verify_authoritative_ns(self):
'''
... Test wheter false is returned when the ns does not match the list. And test if type errors are handeled correctly.
'''
self.assertEqual(verify_authoritative_ns('ns1.google.com', ['ns2.google.com']), False)
self.assertRaises(TypeError, verify_authoritative_ns, 123, ['123'])
self.assertRaises(TypeError, verify_authoritative_ns, "123", "123")
def test_pylint(self):
'''
... Test wheter the coding style is acceptable.
'''
rep = CollectingReporter()
results = Run(['dnsverify.py', '-sn'], reporter=rep, exit=False)
score = results.linter.stats['global_note']
self.assertGreaterEqual(score, 8, "Pylint score to low. Fix your code.")