local pd_service = require 'pd.pd_identify_service'
local lu = require 'luaunit'
local common_def = require 'common_def'

Test_Pd_Identify_Service = {}

function Test_Pd_Identify_Service:test_on_add_drive()
    local on_presence = {}
    local tmp_del = pd_service.del_drive
    local tmp_subhealth = pd_service.set_subhealth_default_values

    pd_service.del_drive = function (drive)
    end

    pd_service.set_subhealth_default_values = function (drive)
    end

    function on_presence:on(add_identify_service)
        add_identify_service(false)
    end
    local drives = {
        presence = 0,
        missing_count = 1,
        dump_info = { startup_time = 1, last_dump_time = 1 },
        on_presence_changed = on_presence,
        unregister_firmware_info = function()
        end,
        set_default_values = function(self)
            self.missing_count = 0
        end
    }
    pd_service:on_add_drive_call_back(drives)
    lu.assertEquals(drives.Missing, 0)
    lu.assertEquals(drives.SerialNumber, common_def.INVALID_STRING)
    lu.assertEquals(drives.FormFactor, 0)
    lu.assertEquals(drives.CommandTimeoutTimes, 0)
    lu.assertEquals(drives.UnexpectedSenseTimes, 0)
    lu.assertEquals(drives.FirmwareStatus, common_def.INVALID_U8)
    lu.assertEquals(drives.PredictedMediaLifeLeftPercent, common_def.INVALID_U8)
    lu.assertEquals(drives.FirmwareStatusError, false)
    lu.assertEquals(drives.Revision, common_def.INVALID_STRING)
    lu.assertEquals(drives.Manufacturer, common_def.INVALID_STRING)
    lu.assertEquals(drives.Model, common_def.INVALID_STRING)
    lu.assertEquals(drives.missing_count, 0)

    pd_service.set_subhealth_default_values = tmp_subhealth
    pd_service.del_drive = tmp_del
end