Skip to content

Commit

Permalink
Add unit tests for event-counters cli (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbud-msft authored Oct 21, 2022
1 parent 5f26a5b commit f53e11b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/event_counters_input/counters_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"COUNTERS_EVENTS:latency_in_ms": {
"value": 2
},
"COUNTERS_EVENTS:missed_to_cache": {
"value": 0
},
"COUNTERS_EVENTS:missed_internal": {
"value": 0
},
"COUNTERS_EVENTS:missed_by_slow_receiver": {
"value": 0
},
"COUNTERS_EVENTS:published": {
"value": 40147
}
}

37 changes: 37 additions & 0 deletions tests/show_event_counters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import sys
from click.testing import CliRunner
from utilities_common.db import Db
import show.main as show

class TestShowEventCounters(object):
@classmethod
def setup_class(cls):
print("SETUP")
os.environ["UTILITIES_UNIT_TESTING"] = "1"

def test_event_counters_show(self):
from .mock_tables import dbconnector
test_path = os.path.dirname(os.path.abspath(__file__))
mock_db_path = os.path.join(test_path, "event_counters_input")
jsonfile_counters = os.path.join(mock_db_path, "counters_db")
dbconnector.dedicated_dbs['COUNTERS_DB'] = jsonfile_counters
runner = CliRunner()
db = Db()
expected_output = """\
name count
----------------------- -------
latency_in_ms 2
missed_by_slow_receiver 0
missed_internal 0
missed_to_cache 0
published 40147
"""

result = runner.invoke(show.cli.commands['event-counters'], [], obj=db)
print(result.exit_code)
print(result.output)
dbconnector.dedicated_dbs['COUNTERS_DB'] = None
assert result.exit_code == 0
assert result.output == expected_output

0 comments on commit f53e11b

Please sign in to comment.