|
8 | 8 |
|
9 | 9 |
|
10 | 10 | def my_setup():
|
11 |
| - global attr, args, endpoints, sensors_conf |
| 11 | + global attr, attr1, args, endpoints, sensors_conf |
| 12 | + |
| 13 | + path = os.getcwd() |
| 14 | + pwFile = os.path.join(path, "tests", "test_data", 'basic_auth') |
12 | 15 |
|
13 | 16 | attr = {'port': 4242, 'prometheus': 9250, 'rawCounters': True, 'protocol': 'http', 'enabled': True,
|
14 | 17 | 'username': 'scale_admin', 'password': 'TXlWZXJ5U3Ryb25nUGFzc3cwcmQhCg==', 'server': 'localhost',
|
15 | 18 | 'serverPort': 9980, 'retryDelay': 60, 'apiKeyName': 'scale_grafana',
|
16 | 19 | 'apiKeyValue': 'c0a910e4-094a-46d8-b04d-c2f73a43fd17', 'caCertPath': False,
|
17 | 20 | 'includeDiskData': False, 'logPath': '/var/log/ibm_bridge_for_grafana', 'logLevel': 10,
|
18 | 21 | 'logFile': 'zserver.log'}
|
| 22 | + |
| 23 | + attr1 = {'port': 4242, 'prometheus': 9250, 'rawCounters': True, 'protocol': 'http', 'enabled': True, |
| 24 | + 'username': 'scale_admin', 'server': 'localhost', |
| 25 | + 'serverPort': 9980, 'retryDelay': 60, 'apiKeyName': 'scale_grafana', |
| 26 | + 'apiKeyValue': 'c0a910e4-094a-46d8-b04d-c2f73a43fd17', 'caCertPath': False, |
| 27 | + 'includeDiskData': False, 'logPath': '/var/log/ibm_bridge_for_grafana', 'logLevel': 10, |
| 28 | + 'logFile': 'zserver.log'} |
| 29 | + |
| 30 | + attr1['password'] = pwFile |
| 31 | + |
19 | 32 | args = {'server': 'localhost', 'port': 9980, 'retryDelay': 60,
|
20 | 33 | 'apiKeyName': 'scale_grafana',
|
21 | 34 | 'apiKeyValue': 'c0a910e4-094a-46d8-b04d-c2f73a43fd17'}
|
@@ -78,10 +91,31 @@ def test_case01():
|
78 | 91 | resp = conf_generator.generate_config()
|
79 | 92 | assert isinstance(resp, str)
|
80 | 93 | assert len(resp) > 0
|
| 94 | + assert "password" in resp |
| 95 | + assert "password_file" not in resp |
81 | 96 |
|
82 | 97 |
|
83 | 98 | @with_setup(my_setup)
|
84 | 99 | def test_case02():
|
| 100 | + with mock.patch('source.metadata.MetadataHandler._MetadataHandler__initializeTables') as md_init: |
| 101 | + with mock.patch('source.metadata.MetadataHandler._MetadataHandler__getSupportedMetrics') as md_supp: |
| 102 | + with mock.patch('source.metadata.MetadataHandler.SensorsConfig', return_value=sensors_conf) as md_sensConf: |
| 103 | + with mock.patch('source.confgenerator.PrometheusConfigGenerator.host_ip', return_value='127.0.0.1'): |
| 104 | + logger = logging.getLogger(__name__) |
| 105 | + args['logger'] = logger |
| 106 | + md = MetadataHandler(**args) |
| 107 | + md.__initializeTables = md_init.return_value |
| 108 | + md.__getSupportedMetrics = md_supp.return_value |
| 109 | + md.SensorsConfig = md_sensConf.return_value |
| 110 | + conf_generator = PrometheusConfigGenerator(logger, md, attr1, endpoints) |
| 111 | + resp = conf_generator.generate_config() |
| 112 | + assert isinstance(resp, str) |
| 113 | + assert len(resp) > 0 |
| 114 | + assert "password_file" in resp |
| 115 | + |
| 116 | + |
| 117 | +@with_setup(my_setup) |
| 118 | +def test_case03(): |
85 | 119 | with mock.patch('source.metadata.MetadataHandler._MetadataHandler__initializeTables') as md_init:
|
86 | 120 | with mock.patch('source.metadata.MetadataHandler._MetadataHandler__getSupportedMetrics') as md_supp:
|
87 | 121 | with mock.patch('source.metadata.MetadataHandler.SensorsConfig', return_value=sensors_conf) as md_sensConf:
|
|
0 commit comments