-- 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 parser_cfg = require 'upgrade.parser_cfg'

TEST_Parser_Cfg = {}

-- 测试parse_dir函数 - 正常路径
function TEST_Parser_Cfg:test_parse_dir_normal_path()
    local file_path = "/tmp/upgrade/Firmware1"
    local dir, firmware_name = parser_cfg.extract_upgrade_file(file_path)

    lu.assertEquals(dir, "/tmp/upgrade/")
    lu.assertEquals(firmware_name, "Firmware1")
end

-- 测试parse_dir函数 - 多级目录
function TEST_Parser_Cfg:test_parse_dir_nested_path()
    local file_path = "/opt/bmc/upgrade/raid/Firmware3"
    local dir, firmware_name = parser_cfg.extract_upgrade_file(file_path)

    lu.assertEquals(dir, "/opt/bmc/upgrade/raid/")
    lu.assertEquals(firmware_name, "Firmware3")
end

-- 测试get_cfgs函数 - 路径为nil
function TEST_Parser_Cfg:test_get_cfgs_nil_path()
    local cfgs = parser_cfg.get_cfgs(nil)

    lu.assertNotNil(cfgs)
    local count = 0
    for _ in pairs(cfgs) do count = count + 1 end
    lu.assertEquals(count, 0, "cfgs should be empty when path is nil")
end

return TEST_Parser_Cfg

