From e2ff78e603f749498d9750f0d355e83fe20333e2 Mon Sep 17 00:00:00 2001 From: Finn Date: Wed, 25 Nov 2015 13:00:33 -0800 Subject: [PATCH] Add basic tests, fixes #18 and fixes #7 --- .travis.yml | 1 + tests.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 .travis.yml create mode 100755 tests.py diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b06a16a --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +script: ./tests.py diff --git a/tests.py b/tests.py new file mode 100755 index 0000000..8b4d8dd --- /dev/null +++ b/tests.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +import json +import os +import sys + +REQUIRED_FIELDS = ['publicKey', 'password', 'contact'] + + +RED = '\033[91m' +GREEN = '\033[92m' +YELLOW = '\033[93m' +LIGHT_PURPLE = '\033[94m' +PURPLE = '\033[95m' +END = '\033[0m' + + +def validate(path): + print("Validating %s" % path) + try: + creds = open(path).read() + peers = json.loads("{%s}" % creds) + hosts = peers.keys() + for host in hosts: + for field in REQUIRED_FIELDS: + if not field in peers[host]: + print(" %sHost %s is missing the %s field!%s" % (RED, host, field, END)) + return False + print(" %sSuccess!%s" % (GREEN, END)) + return True + except ValueError: + print(" %sInvalid JSON!%s" % (RED, END)) + return False + +success = True +for directory, subdirs, files in os.walk('.'): + if len(files) > 0: + for f in files: + if f.endswith('.k'): + result = validate("%s/%s" % (directory, f)) + if not result: + success = False +if not success: + sys.exit(1)