#### Why I did it swsssdk will be deprecated. Use swsscommon instead. #### How to verify it Unit test
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import sys
|
|
import os
|
|
import pytest
|
|
|
|
from swsscommon import swsscommon
|
|
from sonic_py_common.general import load_module_from_source
|
|
|
|
from .mock_connector import MockConnector
|
|
|
|
swsscommon.SonicV2Connector = MockConnector
|
|
|
|
test_path = os.path.dirname(os.path.abspath(__file__))
|
|
modules_path = os.path.dirname(test_path)
|
|
scripts_path = os.path.join(modules_path, "scripts")
|
|
sys.path.insert(0, modules_path)
|
|
|
|
# Load the file under test
|
|
procdockerstatsd_path = os.path.join(scripts_path, 'procdockerstatsd')
|
|
procdockerstatsd = load_module_from_source('procdockerstatsd', procdockerstatsd_path)
|
|
|
|
class TestProcDockerStatsDaemon(object):
|
|
def test_convert_to_bytes(self):
|
|
test_data = [
|
|
('1B', 1),
|
|
('500B', 500),
|
|
('1KB', 1000),
|
|
('500KB', 500000),
|
|
('1MB', 1000000),
|
|
('500MB', 500000000),
|
|
('1MiB', 1048576),
|
|
('500MiB', 524288000),
|
|
('66.41MiB', 69635932),
|
|
('333.6MiB', 349804954),
|
|
('1GiB', 1073741824),
|
|
('500GiB', 536870912000),
|
|
('7.751GiB', 8322572878)
|
|
]
|
|
|
|
pdstatsd = procdockerstatsd.ProcDockerStats(procdockerstatsd.SYSLOG_IDENTIFIER)
|
|
|
|
for test_input, expected_output in test_data:
|
|
res = pdstatsd.convert_to_bytes(test_input)
|
|
assert res == expected_output
|