-- 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.

local lu = require 'luaunit'
local biz_topo_service = require 'biz_topo.biz_topo_service'
local device_service = require 'device.device_service'
local pcie_mock = require 'debug.lualib.pcie_mock.init'

TestPCIeMock = {}

function TestPCIeMock:test_pcie_mock()
    local c_biz_topo_service = biz_topo_service.get_instance
    biz_topo_service.get_instance = function()
        return {
            biz_topo = {
                pcie_addr_info_list = {
                    {mds_obj = {ComponentType = 8, SlotID = 1}},
                    {mds_obj = {ComponentType = 8, SlotID = 2}},
                },
                get_mgmt_connector = function()
                    return true, {
                        Presence = 0,
                        Id = '11',
                        AuxId = '22'
                    }
                end
            }
        }
    end
    local c_device_service = device_service.get_instance
    device_service.get_instance = function()
        return {
            pcie_device_list = {
                {mds = {DeviceType = 8, SlotID = 1}}
            },
            pcie_card_list = {
                {mds = {SlotID = 1, Name = 'SP333'}}
            }
        }
    end

    local pcie_mock_obj = pcie_mock.new()
    local result = pcie_mock_obj:mock_get_connector('PCIe')
    pcie_mock_obj:mock_load_device('PCIe', 2, '33', '44')
    pcie_mock_obj:mock_unload_device('PCIe', 1)
    lu.assertEquals(result[1].Name, 'SP333')

    biz_topo_service.get_instance = c_biz_topo_service
    device_service.get_instance = c_device_service
end