Add unittest for setup_common.py

Refactor the code of setup packages.

Bug: 202820293
Test: atest acloud_test
Change-Id: I949cfe9176b2a7dafc4be3c5119245e25cf62f90
diff --git a/setup/setup_common_test.py b/setup/setup_common_test.py
index 5a00cfc..1f470a7 100644
--- a/setup/setup_common_test.py
+++ b/setup/setup_common_test.py
@@ -17,6 +17,7 @@
 
 from acloud import errors
 from acloud.internal.lib import driver_test_lib
+from acloud.internal.lib import utils
 from acloud.setup import setup_common
 
 
@@ -38,6 +39,30 @@
   Version table:
 """
 
+    def setUp(self):
+        """Create mock objects."""
+        super().setUp()
+        self._mock_checkoutput = self.Patch(utils, "CheckOutput")
+
+    def testCheckCmdOutput(self):
+        """Test CheckCmdOutput."""
+        cmd = "fake_command"
+        setup_common.CheckCmdOutput(cmd)
+        self._mock_checkoutput.assert_called_once_with(cmd)
+
+    def testInstallPackage(self):
+        """Test InstallPackage."""
+        package = "fake_pkg"
+        self.Patch(setup_common, "PackageInstalled", return_value=True)
+        setup_common.InstallPackage(package)
+        self._mock_checkoutput.assert_called_once_with(
+            "sudo apt-get --assume-yes install fake_pkg",
+            shell=True, stderr=subprocess.STDOUT)
+
+        self.Patch(setup_common, "PackageInstalled", return_value=False)
+        with self.assertRaises(errors.PackageInstallError):
+            setup_common.InstallPackage(package)
+
     # pylint: disable=invalid-name
     def testPackageNotInstalled(self):
         """"Test PackageInstalled return False when Installed status is (None). """
@@ -49,6 +74,14 @@
         self.assertFalse(
             setup_common.PackageInstalled("fake_package"))
 
+        # Test with the package didn't install in host.
+        self.Patch(
+            setup_common,
+            "CheckCmdOutput",
+            return_value="")
+        self.assertFalse(
+            setup_common.PackageInstalled("fake_package"))
+
     def testUnableToLocatePackage(self):
         """"Test PackageInstalled return False if unable to locate package."""
         self.Patch(