Skip to content

Commit f53e11b

Browse files
authored
Add unit tests for event-counters cli (#2)
1 parent 5f26a5b commit f53e11b

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"COUNTERS_EVENTS:latency_in_ms": {
3+
"value": 2
4+
},
5+
"COUNTERS_EVENTS:missed_to_cache": {
6+
"value": 0
7+
},
8+
"COUNTERS_EVENTS:missed_internal": {
9+
"value": 0
10+
},
11+
"COUNTERS_EVENTS:missed_by_slow_receiver": {
12+
"value": 0
13+
},
14+
"COUNTERS_EVENTS:published": {
15+
"value": 40147
16+
}
17+
}
18+

tests/show_event_counters.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import sys
3+
from click.testing import CliRunner
4+
from utilities_common.db import Db
5+
import show.main as show
6+
7+
class TestShowEventCounters(object):
8+
@classmethod
9+
def setup_class(cls):
10+
print("SETUP")
11+
os.environ["UTILITIES_UNIT_TESTING"] = "1"
12+
13+
def test_event_counters_show(self):
14+
from .mock_tables import dbconnector
15+
test_path = os.path.dirname(os.path.abspath(__file__))
16+
mock_db_path = os.path.join(test_path, "event_counters_input")
17+
jsonfile_counters = os.path.join(mock_db_path, "counters_db")
18+
dbconnector.dedicated_dbs['COUNTERS_DB'] = jsonfile_counters
19+
runner = CliRunner()
20+
db = Db()
21+
expected_output = """\
22+
name count
23+
----------------------- -------
24+
latency_in_ms 2
25+
missed_by_slow_receiver 0
26+
missed_internal 0
27+
missed_to_cache 0
28+
published 40147
29+
"""
30+
31+
result = runner.invoke(show.cli.commands['event-counters'], [], obj=db)
32+
print(result.exit_code)
33+
print(result.output)
34+
dbconnector.dedicated_dbs['COUNTERS_DB'] = None
35+
assert result.exit_code == 0
36+
assert result.output == expected_output
37+

0 commit comments

Comments
 (0)