Пример #1
0
    def testPackageBuildFailure(self):
        """Test handling of raised BuildPackageFailure."""
        tempdir = osutils.TempDir(base_dir=self.tempdir)
        self.PatchObject(osutils, 'TempDir', return_value=tempdir)

        pkgs = ['cat/pkg', 'foo/bar']
        expected = [('cat', 'pkg'), ('foo', 'bar')]

        result = test_service.BuildTargetUnitTestResult(1, None)
        result.failed_cpvs = [
            portage_util.SplitCPV(p, strict=False) for p in pkgs
        ]
        self.PatchObject(test_service,
                         'BuildTargetUnitTest',
                         return_value=result)

        input_msg = self._GetInput(board='board', result_path=self.tempdir)
        output_msg = self._GetOutput()

        rc = test_controller.BuildTargetUnitTest(input_msg, output_msg,
                                                 self.api_config)

        self.assertEqual(
            controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
        self.assertTrue(output_msg.failed_packages)
        failed = []
        for pi in output_msg.failed_packages:
            failed.append((pi.category, pi.package_name))
        self.assertCountEqual(expected, failed)
Пример #2
0
 def testNoBuildTargetFails(self):
     """Test missing build target name fails."""
     input_msg = self._GetInput(result_path=self.tempdir)
     output_msg = self._GetOutput()
     with self.assertRaises(cros_build_lib.DieSystemExit):
         test_controller.BuildTargetUnitTest(input_msg, output_msg,
                                             self.api_config)
Пример #3
0
 def testNoArgumentFails(self):
     """Test no arguments fails."""
     input_msg = self._GetInput()
     output_msg = self._GetOutput()
     with self.assertRaises(cros_build_lib.DieSystemExit):
         test_controller.BuildTargetUnitTest(input_msg, output_msg,
                                             self.api_config)
Пример #4
0
 def testNoResultPathFails(self):
     """Test missing result path fails."""
     # Missing result_path.
     input_msg = self._GetInput(board='board')
     output_msg = self._GetOutput()
     with self.assertRaises(cros_build_lib.DieSystemExit):
         test_controller.BuildTargetUnitTest(input_msg, output_msg,
                                             self.api_config)
Пример #5
0
    def testValidateOnly(self):
        """Sanity check that a validate only call does not execute any logic."""
        patch = self.PatchObject(test_service, 'BuildTargetUnitTest')

        input_msg = self._GetInput(board='board', result_path=self.tempdir)
        test_controller.BuildTargetUnitTest(input_msg, self._GetOutput(),
                                            self.validate_only_config)
        patch.assert_not_called()
Пример #6
0
    def testMockCall(self):
        """Test that a mock call does not execute logic, returns mocked value."""
        patch = self.PatchObject(test_service, 'BuildTargetUnitTest')

        input_msg = self._GetInput(board='board', result_path=self.tempdir)
        response = self._GetOutput()
        test_controller.BuildTargetUnitTest(input_msg, response,
                                            self.mock_call_config)
        patch.assert_not_called()
        self.assertEqual(response.tarball_path,
                         os.path.join(input_msg.result_path, 'unit_tests.tar'))
Пример #7
0
    def testMockError(self):
        """Test that a mock error does not execute logic, returns mocked value."""
        patch = self.PatchObject(test_service, 'BuildTargetUnitTest')

        input_msg = self._GetInput(board='board', result_path=self.tempdir)
        response = self._GetOutput()
        rc = test_controller.BuildTargetUnitTest(input_msg, response,
                                                 self.mock_error_config)
        patch.assert_not_called()
        self.assertEqual(
            controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc)
        self.assertTrue(response.failed_packages)
        self.assertEqual(response.failed_packages[0].category, 'foo')
        self.assertEqual(response.failed_packages[0].package_name, 'bar')
        self.assertEqual(response.failed_packages[1].category, 'cat')
        self.assertEqual(response.failed_packages[1].package_name, 'pkg')
Пример #8
0
    def testBuildTargetUnitTest(self):
        """Test BuildTargetUnitTest successful call."""
        input_msg = self._GetInput(board='board', result_path=self.tempdir)

        result = test_service.BuildTargetUnitTestResult(0, None)
        self.PatchObject(test_service,
                         'BuildTargetUnitTest',
                         return_value=result)

        tarball_result = os.path.join(input_msg.result_path, 'unit_tests.tar')
        self.PatchObject(test_service,
                         'BuildTargetUnitTestTarball',
                         return_value=tarball_result)

        response = self._GetOutput()
        test_controller.BuildTargetUnitTest(input_msg, response,
                                            self.api_config)
        self.assertEqual(response.tarball_path,
                         os.path.join(input_msg.result_path, 'unit_tests.tar'))
Пример #9
0
    def testOtherBuildScriptFailure(self):
        """Test build script failure due to non-package emerge error."""
        tempdir = osutils.TempDir(base_dir=self.tempdir)
        self.PatchObject(osutils, 'TempDir', return_value=tempdir)

        result = test_service.BuildTargetUnitTestResult(1, None)
        self.PatchObject(test_service,
                         'BuildTargetUnitTest',
                         return_value=result)

        pkgs = ['foo/bar', 'cat/pkg']
        blacklist = [portage_util.SplitCPV(p, strict=False) for p in pkgs]
        input_msg = self._GetInput(board='board',
                                   result_path=self.tempdir,
                                   empty_sysroot=True,
                                   blacklist=blacklist)
        output_msg = self._GetOutput()

        rc = test_controller.BuildTargetUnitTest(input_msg, output_msg,
                                                 self.api_config)

        self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
        self.assertFalse(output_msg.failed_packages)
Пример #10
0
    def testBuildTargetUnitTest(self):
        """Test BuildTargetUnitTest successful call."""
        pkgs = ['foo/bar', 'cat/pkg']
        packages = [package_info.SplitCPV(p, strict=False) for p in pkgs]
        input_msg = self._GetInput(board='board',
                                   result_path=self.tempdir,
                                   packages=packages)

        result = test_service.BuildTargetUnitTestResult(0, None)
        self.PatchObject(test_service,
                         'BuildTargetUnitTest',
                         return_value=result)

        tarball_result = os.path.join(input_msg.result_path, 'unit_tests.tar')
        self.PatchObject(test_service,
                         'BuildTargetUnitTestTarball',
                         return_value=tarball_result)

        response = self._GetOutput()
        test_controller.BuildTargetUnitTest(input_msg, response,
                                            self.api_config)
        self.assertEqual(response.tarball_path,
                         os.path.join(input_msg.result_path, 'unit_tests.tar'))