Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Add unit tests for 'show platform ...' commands #1021

Merged
merged 15 commits into from
Aug 5, 2020
Merged
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions tests/show_platform_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import sys
import textwrap

import mock
from click.testing import CliRunner
from unittest import TestCase
lguohan marked this conversation as resolved.
Show resolved Hide resolved

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
sys.path.insert(0, test_path)
sys.path.insert(0, modules_path)

import show.main as show


TEST_PLATFORM = "x86_64-mlnx_msn2700-r0"
TEST_HWSKU = "Mellanox-SN2700"
TEST_ASIC_TYPE = "mellanox"


"""
Note: The following 'show platform' commands simply call other SONiC
CLI utilities, so the unit tests for the other utilities are expected
to cover testing their functionality:

show platform fan
show platform firmware
show platform mlnx
show platform psustatus
show platform ssdhealth
show platform syseeprom
show platform temperature
"""

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

# Test 'show platform summary'
def test_summary(self):
expected_output = """\
Platform: {}
HwSKU: {}
ASIC: {}
""".format(TEST_PLATFORM, TEST_HWSKU, TEST_ASIC_TYPE)

with mock.patch("show.main.get_hw_info_dict",
return_value={"platform": TEST_PLATFORM, "hwsku": TEST_HWSKU, "asic_type": TEST_ASIC_TYPE}):
runner = CliRunner()
result = runner.invoke(show.cli.commands["platform"].commands["summary"], [])
assert result.output == textwrap.dedent(expected_output)

@classmethod
def teardown_class(cls):
print("TEARDOWN")
os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1])
os.environ["UTILITIES_UNIT_TESTING"] = "0"