KeeperOfTheSevenKeys
KeeperOfTheSevenKeys

Reputation: 69

How can I create a unit test for a memory dump without mocking?

In Javascript, I have these two functions:

const promiseMemoryDump = async (address1, address2, outputFile) => {
  if (getPlatform() === 'linux') {
      await promiseExec(`memdump -s ${address1} -l ${address2} -o ${outputFile}`)
  }
}
const promiseExtractStringFromBinary = async (file, string) => {
  if (getPlatform() === 'linux') {
    await promiseExec(`strings ${file} | grep ${string} -B 1 | head -n 1`)
  }
}

I also have a function that performs these actions:

const getFirmware = async () => {
  await promiseMemoryDump(0x200000, 0x100000, '/home/memorydump')
  if (await promiseFileExists('/home/memorydump')) {
    const stringsReturn = await promiseExtractStringFromBinary('/home/memorydump', 'FW ver')
    await promiseExec('/bin/rm -f /home/memorydump')
    return stringsReturn.stdout.trim()
  }
  return null
}

How can I properly write unit test(s) to:

What should I mock and what shouldn't?

Thanks

Upvotes: 0

Views: 38

Answers (0)

Related Questions