blob: e7e591120965301b4dd02eba7f6f3202c1d83a08 [file] [log] [blame]
#!/usr/bin/env python
#
# Copyright 2017 - The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
from metrics import time_sync_metric
from tests import fake
class TimeSyncMetricTest(unittest.TestCase):
"""Class for testing TimeSyncMetric."""
def test_yes_time_sync(self):
stdout_string = "NTP synchronized: yes"
FAKE_RESULT = fake.FakeResult(stdout=stdout_string)
fake_shell = fake.MockShellCommand(fake_result=FAKE_RESULT)
metric_obj = time_sync_metric.TimeSyncMetric(shell=fake_shell)
expected_result = {
time_sync_metric.TimeSyncMetric.IS_SYNCHRONIZED: True,
}
self.assertEqual(expected_result, metric_obj.gather_metric())
def test_no_time_sync(self):
stdout_string = 'NTP synchronized: no'
FAKE_RESULT = fake.FakeResult(stdout=stdout_string)
fake_shell = fake.MockShellCommand(fake_result=FAKE_RESULT)
metric_obj = time_sync_metric.TimeSyncMetric(shell=fake_shell)
expected_result = {
time_sync_metric.TimeSyncMetric.IS_SYNCHRONIZED: False,
}
self.assertEqual(expected_result, metric_obj.gather_metric())
if __name__ == '__main__':
unittest.main()