-- Copyright (c) 2024 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 ncsi_lldp = require 'ncsi.ncsi_lldp'
local ncsi_comm = require 'ncsi.ncsi_comm'

-- 测试套件
TestNCSILldp = {}

function TestNCSILldp:test_process_lldp_over_ncsi_state()
    local lldp_obj = {
        is_recovered = false,
        is_process = false,
        process_lldp_over_ncsi_state = ncsi_lldp.process_lldp_over_ncsi_state,
        set_lldp_state = function(obj, state)
        end,
        recover_vlan_enable_state = function(obj)
            obj.is_recovered = true
        end
    }
    -- 执行测试
    lldp_obj:process_lldp_over_ncsi_state(false)

    -- 验证结果
    lu.assertEquals(lldp_obj.is_recovered, true)
    lu.assertEquals(lldp_obj.is_process, false)
end

function TestNCSILldp:test_set_lldp_state()
    local database = {}
    local origin_get_ncsi_eth_name = ncsi_comm.get_instance().get_ncsi_eth_name
    ncsi_comm.get_instance().get_ncsi_eth_name = function(self_comm)
        return 'eth0'
    end
    database.select = function(db_self, table)
        if table == db_self.NcsiNCPortInfo then
            return {
                all = function ()
                    return {}
                end,
                first = function ()
                    return nil
                end
            }
        end
    end
    local lldp_obj = {
        db = database,
        is_recovered = false,
        is_process = false,
        set_lldp_state = ncsi_lldp.set_lldp_state,
        recover_vlan_enable_state = ncsi_lldp.recover_vlan_enable_state
    }
    lldp_obj:set_lldp_state(true)
    lldp_obj:recover_vlan_enable_state()
    ncsi_comm.get_instance().get_ncsi_eth_name = origin_get_ncsi_eth_name
end

return TestNCSILldp