2016-11-12 13:22:23 +03:00
|
|
|
import unittest
|
|
|
|
import json
|
|
|
|
import os
|
2016-11-14 14:57:17 +03:00
|
|
|
import re
|
2016-11-12 13:22:23 +03:00
|
|
|
|
|
|
|
class TestLoadConfig(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_main_conf(self):
|
|
|
|
# Load base configurations
|
|
|
|
surok_conf = '/etc/surok/conf/surok.json'
|
|
|
|
# Read config file
|
|
|
|
f = open(surok_conf, 'r')
|
|
|
|
conf = json.loads(f.read())
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
self.assertIn('confd', conf)
|
|
|
|
self.assertTrue(os.path.isdir(conf['confd']))
|
2016-11-14 14:57:17 +03:00
|
|
|
self.assertIn('wait_time', conf)
|
|
|
|
self.assertIn('lock_dir', conf)
|
|
|
|
self.assertTrue(os.path.isdir(conf['lock_dir']))
|
|
|
|
|
|
|
|
|
|
|
|
class TestLogger(unittest.TestCase):
|
|
|
|
|
2017-01-25 13:11:51 +03:00
|
|
|
def test_debug(self):
|
|
|
|
from surok.logger import Logger
|
|
|
|
m = Logger()
|
|
|
|
self.assertIn('DEBUG', m.testing('debug','log message'))
|
|
|
|
|
2016-11-14 14:57:17 +03:00
|
|
|
def test_info(self):
|
2017-01-25 13:11:51 +03:00
|
|
|
from surok.logger import Logger
|
|
|
|
m = Logger()
|
|
|
|
self.assertIn('INFO', m.testing('info','log message'))
|
2016-11-14 14:57:17 +03:00
|
|
|
|
|
|
|
def test_warning(self):
|
2017-01-25 13:11:51 +03:00
|
|
|
from surok.logger import Logger
|
|
|
|
m = Logger()
|
|
|
|
self.assertIn('WARNING', m.testing('warning','log message'))
|
2016-11-14 14:57:17 +03:00
|
|
|
|
|
|
|
def test_error(self):
|
2017-01-25 13:11:51 +03:00
|
|
|
from surok.logger import Logger
|
|
|
|
m = Logger()
|
|
|
|
self.assertIn('ERROR', m.testing('error','log message'))
|
2016-11-12 13:22:23 +03:00
|
|
|
|
|
|
|
|
2016-11-14 15:59:39 +03:00
|
|
|
class TestMemcachedDiscovery(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_discovery_memcache(self):
|
|
|
|
from surok.system import discovery_memcached
|
2017-01-25 13:11:51 +03:00
|
|
|
from surok.discovery import Discovery
|
2016-11-14 15:59:39 +03:00
|
|
|
# Load base configurations
|
|
|
|
surok_conf = '/etc/surok/conf/surok.json'
|
|
|
|
# Read config file
|
|
|
|
f = open(surok_conf, 'r')
|
|
|
|
conf = json.loads(f.read())
|
|
|
|
f.close()
|
2017-01-25 13:11:51 +03:00
|
|
|
d=Discovery(conf)
|
2016-11-14 15:59:39 +03:00
|
|
|
self.assertEqual(discovery_memcached(conf), [])
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetGroup(unittest.TestCase):
|
|
|
|
|
2017-01-25 13:11:51 +03:00
|
|
|
def test_get_group_from_service(self):
|
|
|
|
from surok.discovery import DiscoveryTemplate
|
|
|
|
d=DiscoveryTemplate({})
|
|
|
|
self.assertEqual('xxx.yyy.zzz',d.get_group({'group':'xxx.yyy.zzz'}, {}))
|
|
|
|
|
|
|
|
def test_get_group_from_env(self):
|
|
|
|
from surok.discovery import DiscoveryTemplate
|
|
|
|
d=DiscoveryTemplate({})
|
|
|
|
self.assertEqual('xxx.yyy.zzz',d.get_group({}, {'env':{'SUROK_DISCOVERY_GROUP':'xxx.yyy.zzz'}}))
|
|
|
|
|
|
|
|
def test_get_group_from_marathon_id(self):
|
|
|
|
from surok.discovery import DiscoveryTemplate
|
|
|
|
d=DiscoveryTemplate({})
|
|
|
|
self.assertEqual('xxx.yyy.zzz',d.get_group({}, {'env':{'MARATHON_APP_ID':'/zzz/yyy/xxx/www'}}))
|
|
|
|
|
2016-11-14 15:59:39 +03:00
|
|
|
|
2016-11-12 13:22:23 +03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|