local lu = require 'luaunit'
local base = require 'retimer.retimer_base'
local retimer = require 'retimer.retimer'
local intf_client = require 'general_hardware.client'

TestBaseTest = {}

function TestBaseTest:test_start()
    base.agent = {
        start = function()
            return true
        end,
        stop = function()
            return true
        end}
    base.upgrade_status = 1
    base.component_idex = 7
    base.retimer_obj = {TemperatureCelsius = 22, ChipName = "ExpBoard6 Retimer1", ChipType = 7
        ,FirmwareStorageChip = {
            Write = function() 
                return true
            end
        }
    }
    base.position = "0202"
    base:init()
    base:cleanup()
    base:register_firmware_info()
    local res = base:get_upgrade_status()
    lu.assertEquals(res, 1)
    res = base:get_chip_type()
    lu.assertEquals(res, 7)
    res = base:get_chip_temp()
    lu.assertEquals(res, 22)
end

function TestBaseTest:test_trans_fw_to_ref_eeprom()
    local res = base:trans_fw_to_ref_eeprom("12345678")
    lu.assertEquals(res, true)
end

function TestBaseTest:test_update_firmware_version()
    local orig_intf_fun = intf_client.GetFirmwareInfoObjects
    intf_client.GetFirmwareInfoObjects = function()
        return {}
    end
    retimer.fw_id = 'fw_id'
    retimer.retimer_obj = {
        FirmwareVersion = 'FirmwareVersion'
    }
    local ret = retimer:update_firmware_version()
    lu.assertEquals(ret, nil)
    intf_client.GetFirmwareInfoObjects = function()
        return {
            ['/bmc/kepler/UpdateService/FirmwareInventory/fw_id'] = {
                Version = 'Version'
            }
        }
    end
    local ret = retimer:update_firmware_version()
    lu.assertEquals(ret, nil)

    intf_client.GetFirmwareInfoObjects = orig_intf_fun
end

