Skip to content

Commit

Permalink
update unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdwhdw committed Jan 21, 2025
1 parent d8b5708 commit c8104f5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/host_modules/image_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import stat
import pytest
import json
from unittest import mock
from host_modules.image_service import ImageService

Expand Down Expand Up @@ -375,9 +376,9 @@ def test_checksum_general_exception(
@mock.patch("dbus.service.BusName")
@mock.patch("dbus.service.Object.__init__")
@mock.patch("subprocess.check_output")
def test_list_success(self, mock_check_output, MockInit, MockBusName, MockSystemBus):
def test_list_image_success(self, mock_check_output, MockInit, MockBusName, MockSystemBus):
"""
Test that the `list` method successfully lists the current, next, and available SONiC images.
Test that the `list_images` method successfully lists the current, next, and available SONiC images.
"""
# Arrange
image_service = ImageService(mod_name="image_service")
Expand All @@ -391,7 +392,8 @@ def test_list_success(self, mock_check_output, MockInit, MockBusName, MockSystem
mock_check_output.return_value = mock_output.encode()

# Act
rc, images = image_service.list()
rc, images_json = image_service.list_images()
images = json.loads(images_json)

# Assert
assert rc == 0, "wrong return value"
Expand All @@ -407,9 +409,9 @@ def test_list_success(self, mock_check_output, MockInit, MockBusName, MockSystem
@mock.patch("dbus.service.BusName")
@mock.patch("dbus.service.Object.__init__")
@mock.patch("subprocess.check_output")
def test_list_failed(self, mock_check_output, MockInit, MockBusName, MockSystemBus):
def test_list_image_failed(self, mock_check_output, MockInit, MockBusName, MockSystemBus):
"""
Test that the `list` method fails when the subprocess command returns a non-zero exit code.
Test that the `list_image` method fails when the subprocess command returns a non-zero exit code.
"""
# Arrange
image_service = ImageService(mod_name="image_service")
Expand All @@ -418,7 +420,7 @@ def test_list_failed(self, mock_check_output, MockInit, MockBusName, MockSystemB
)

# Act
rc, msg = image_service.list()
rc, msg = image_service.list_images()

# Assert
assert rc != 0, "wrong return value"
Expand Down

0 comments on commit c8104f5

Please sign in to comment.