def testArgumentHandling(self): """Test the arguments get processed and passed correctly.""" sysroot_path = '/sysroot/path' sysroot = sysroot_lib.Sysroot(sysroot_path) create_patch = self.PatchObject(sysroot_service, 'Create', return_value=sysroot) target_patch = self.PatchObject(build_target_util, 'BuildTarget') rc_patch = self.PatchObject(sysroot_service, 'SetupBoardRunConfig') # Default values. board = 'board' profile = None force = False upgrade_chroot = True in_proto = self._InputProto(build_target=board, profile=profile, replace=force, current=not upgrade_chroot) out_proto = self._OutputProto() sysroot_controller.Create(in_proto, out_proto, self.api_config) # Default value checks. target_patch.assert_called_with(name=board, profile=profile) rc_patch.assert_called_with(force=force, upgrade_chroot=upgrade_chroot) self.assertEqual(board, out_proto.sysroot.build_target.name) self.assertEqual(sysroot_path, out_proto.sysroot.path) # Not default values. create_patch.reset_mock() board = 'board' profile = 'profile' force = True upgrade_chroot = False in_proto = self._InputProto(build_target=board, profile=profile, replace=force, current=not upgrade_chroot) out_proto = self._OutputProto() sysroot_controller.Create(in_proto, out_proto, self.api_config) # Not default value checks. target_patch.assert_called_with(name=board, profile=profile) rc_patch.assert_called_with(force=force, upgrade_chroot=upgrade_chroot) self.assertEqual(board, out_proto.sysroot.build_target.name) self.assertEqual(sysroot_path, out_proto.sysroot.path)
def testArgumentValidation(self): """Test the input argument validation.""" # Error when no name provided. in_proto = self._InputProto() out_proto = self._OutputProto() with self.assertRaises(cros_build_lib.DieSystemExit): sysroot_controller.Create(in_proto, out_proto, self.api_config) # Valid when board passed. result = sysroot_lib.Sysroot('/sysroot/path') patch = self.PatchObject(sysroot_service, 'Create', return_value=result) in_proto = self._InputProto('board') out_proto = self._OutputProto() sysroot_controller.Create(in_proto, out_proto, self.api_config) patch.assert_called_once()
def testMockError(self): """Sanity check that a mock error does not execute any logic.""" patch = self.PatchObject(sysroot_service, 'Create') request = self._InputProto() response = self._OutputProto() rc = sysroot_controller.Create(request, response, self.mock_error_config) patch.assert_not_called() self.assertEqual(controller.RETURN_CODE_UNRECOVERABLE, rc)
def testValidateOnly(self): """Sanity check that a validate only call does not execute any logic.""" patch = self.PatchObject(sysroot_service, 'Create') board = 'board' profile = None force = False upgrade_chroot = True in_proto = self._InputProto(build_target=board, profile=profile, replace=force, current=not upgrade_chroot) sysroot_controller.Create(in_proto, self._OutputProto(), self.validate_only_config) patch.assert_not_called()
def testArgumentHandling(self): """Test the arguments get processed and passed correctly.""" sysroot_path = '/sysroot/path' sysroot = sysroot_lib.Sysroot(sysroot_path) create_patch = self.PatchObject(sysroot_service, 'Create', return_value=sysroot) rc_patch = self.PatchObject(sysroot_service, 'SetupBoardRunConfig') # Default values. board = 'board' profile = None force = False upgrade_chroot = True in_proto = self._InputProto(build_target=board, profile=profile, replace=force, current=not upgrade_chroot) out_proto = self._OutputProto() sysroot_controller.Create(in_proto, out_proto, self.api_config) # Default value checks. rc_patch.assert_called_with(force=force, upgrade_chroot=upgrade_chroot, package_indexes=[]) self.assertEqual(board, out_proto.sysroot.build_target.name) self.assertEqual(sysroot_path, out_proto.sysroot.path) # Not default values. create_patch.reset_mock() board = 'board' profile = 'profile' force = True upgrade_chroot = False package_indexes = [ common_pb2.PackageIndexInfo( snapshot_sha='SHA', snapshot_number=5, build_target=common_pb2.BuildTarget(name=board), location='LOCATION', profile=common_pb2.Profile(name=profile)), common_pb2.PackageIndexInfo( snapshot_sha='SHA2', snapshot_number=4, build_target=common_pb2.BuildTarget(name=board), location='LOCATION2', profile=common_pb2.Profile(name=profile)) ] in_proto = self._InputProto(build_target=board, profile=profile, replace=force, current=not upgrade_chroot, package_indexes=package_indexes) out_proto = self._OutputProto() sysroot_controller.Create(in_proto, out_proto, self.api_config) # Not default value checks. rc_patch.assert_called_with( force=force, package_indexes=[ binpkg.PackageIndexInfo.from_protobuf(x) for x in package_indexes ], upgrade_chroot=upgrade_chroot) self.assertEqual(board, out_proto.sysroot.build_target.name) self.assertEqual(sysroot_path, out_proto.sysroot.path)