From c62a38eb7fc1a303de3f74304897ffa34712975e Mon Sep 17 00:00:00 2001 From: Denis Zheleztsov Date: Mon, 14 Nov 2016 14:57:17 +0300 Subject: [PATCH] logger test and fix debian/install --- .travis.yml | 2 ++ build/build.sh | 3 ++- build/functions.sh | 32 ++++++++++++++++++++++++++++++++ build/tests.py | 28 +++++++++++++++++++++++++++- debian/install | 1 + 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4d04821..fd28d66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,8 @@ services: before_install: - docker pull ubuntu:xenial - cd build && ./build.sh surok_image + - ./build.sh alpine + - ./build.sh centos script: - ./runtests.sh diff --git a/build/build.sh b/build/build.sh index ed6612a..088fed7 100755 --- a/build/build.sh +++ b/build/build.sh @@ -5,7 +5,7 @@ set -e . functions.sh function usage() { - echo "$0 " + echo "$0 " } case $1 in @@ -18,5 +18,6 @@ case $1 in surok_image) build_surok_base rebuild ;; surok_image_no_rebuild) build_surok_base ;; alpine) build_alpine ;; + centos) build_centos ;; *) usage ;; esac diff --git a/build/functions.sh b/build/functions.sh index 406702c..3006117 100644 --- a/build/functions.sh +++ b/build/functions.sh @@ -93,3 +93,35 @@ ENTRYPOINT cd /opt/surok && python3 surok.py -c /etc/surok/conf/surok.json EOF docker build -t surok_alpine -f Dockerfile.alpine . } + +function build_centos() { + copy_surok + cat > Dockerfile.centos < + +RUN yum -y install epel-release +RUN yum -y install python34 + +# Install pip +RUN cd /tmp && curl -O https://bootstrap.pypa.io/get-pip.py +RUN cd /tmp && python3.4 get-pip.py + +# Install surok +COPY surok /opt/surok +RUN mkdir /etc/surok +RUN ln -s /opt/surok/conf /etc/surok/conf +RUN ln -s /opt/surok/conf.d /etc/surok/conf.d +RUN ln -s /opt/surok/templates /etc/surok/templates + +# Install surok depends +RUN cd /opt/surok && pip3 install -r requriments.txt + +# Cleanup +RUN yum clean all + +ENTRYPOINT cd /opt/surok && python3 surok.py -c /etc/surok/conf/surok.json +EOF + docker build -t surok_centos -f Dockerfile.centos . +} diff --git a/build/tests.py b/build/tests.py index a194afc..5faec71 100644 --- a/build/tests.py +++ b/build/tests.py @@ -1,11 +1,11 @@ import unittest import json import os +import re class TestLoadConfig(unittest.TestCase): - def test_main_conf(self): # Load base configurations surok_conf = '/etc/surok/conf/surok.json' @@ -17,6 +17,32 @@ class TestLoadConfig(unittest.TestCase): self.assertIn('confd', conf) self.assertTrue(os.path.isdir(conf['confd'])) self.assertIn('domain', conf) + self.assertIn('wait_time', conf) + self.assertIn('lock_dir', conf) + self.assertTrue(os.path.isdir(conf['lock_dir'])) + + +class TestLogger(unittest.TestCase): + + def test_info(self): + from surok.logger import make_message + m = make_message + self.assertIn('INFO', m({'level': 'info', 'raw': 'log message'})) + + def test_warning(self): + from surok.logger import make_message + m = make_message + self.assertIn('WARNING', m({'level': 'warning', 'raw': 'log message'})) + + def test_error(self): + from surok.logger import make_message + m = make_message + self.assertIn('ERROR', m({'level': 'error', 'raw': 'log message'})) + + def test_info(self): + from surok.logger import make_message + m = make_message + self.assertIn('DEBUG', m({'level': 'debug', 'raw': 'log message'})) if __name__ == '__main__': diff --git a/debian/install b/debian/install index a8b780d..74eab76 100644 --- a/debian/install +++ b/debian/install @@ -1,6 +1,7 @@ conf/surok.json etc/surok/conf surok/templates.py opt/surok/surok surok/system.py opt/surok/surok +surok/logger.py opt/surok/surok surok/__init__.py opt/surok/surok surok/discovery.py opt/surok/surok surok.py opt/surok