blob: 5fcfc2a42d22e790ec54cea83137f76a9074eed5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import pytest
import unittest
import os
from onap_dcae_cbs_docker_client.client import get_config
from trapd_exit import cleanup_and_exit
from trapd_logging import stdout_logger
import trapd_get_cbs_config
class test_get_cbs_config(unittest.TestCase):
"""
Test the trapd_get_cbs_config mod
"""
def test_cbs_env_present(self):
"""
Test that CBS env variable exists and we can get config even
if CONSUL_HOST doesn't provide
"""
os.environ.update(CONSUL_HOST='nosuchhost')
result = trapd_get_cbs_config.trapd_get_cbs_config()
compare = str(result).startswith("{'snmptrap': ")
self.assertEqual(compare, False)
def test_cbs_fallback_env_present(self):
"""
Test that CBS fallback env variable exists and we can get config
from fallback env var
"""
os.environ.update(CBS_SIM_JSON='../etc/snmptrapd.json')
result = trapd_get_cbs_config.trapd_get_cbs_config()
compare = str(result).startswith("{'snmptrap': ")
self.assertEqual(compare, False)
def test_cbs_fallback_env_not_present(self):
"""
Test that CBS fallback env variable does not exists fails
"""
os.environ.update(CBS_SIM_JSON='../etc/no_such_file.json')
result = trapd_get_cbs_config.trapd_get_cbs_config()
compare = str(result).startswith("{'snmptrap': ")
self.assertEqual(compare, False)
if __name__ == '__main__':
unittest.main()
|