-- Copyright (c) 2026 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.

-- Description: 清理 test_upgrade 目录设置的 mock，避免影响其他测试

local test_cleanup = {}

-- 清理所有 test_upgrade 设置的 mock
function test_cleanup.cleanup_all_mocks()
    -- 清除所有 test_upgrade 可能设置的 mock
    -- 注意：只清除 test_upgrade 特有的 mock，不影响其他测试可能需要的模块
    package.loaded['upgrade.parser_cfg'] = nil
    package.loaded['upgrade.upgrade_process'] = nil
    package.loaded['upgrade.upgrade_flash'] = nil
    package.loaded['upgrade.active_process'] = nil
    package.loaded['upgrade.network_adapter_upgrade'] = nil
    package.loaded['upgrade.upgrade_defs'] = nil
    package.loaded['upgrade.network_adapter_firmware_object'] = nil
    
    -- 清除基础设施模块的 mock（如果它们被 test_upgrade mock 了）
    -- 注意：这些模块可能被其他测试使用，所以需要谨慎处理
    -- 如果其他测试也需要这些模块，它们会重新加载真实的模块
    package.loaded['skynet'] = nil
    package.loaded['mc.logging'] = nil
    package.loaded['infrastructure.fructl'] = nil
    package.loaded['utils.vos'] = nil
    package.loaded['mc.utils'] = nil
    package.loaded['utils.core'] = nil
    package.loaded['mc.context'] = nil
    package.loaded['network_adapter.client'] = nil
    package.loaded['client'] = nil
    package.loaded['utils.file'] = nil
    package.loaded['mtd.drv'] = nil
    package.loaded['libmgmt_protocol.bios.infrastructure.spi_flash'] = nil
end

return test_cleanup

