Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Jun 29, 2024
1 parent a4f19a5 commit 34a6359
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cli/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = ({ commandProcessor, root }) => {
params: '<filename>',
handler: (args) => {
const BinaryCommand = require('../cmd/binary');
return new BinaryCommand().inspectApplicationBinary(args.params.filename);
return new BinaryCommand().inspectBinary(args.params.filename);
},
examples: {
'$0 $command firmware.bin': 'Describe contents of firmware.bin'
Expand Down
29 changes: 29 additions & 0 deletions src/cmd/binary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,35 @@ describe('Binary Inspect', () => {
});
});

describe('_parseBinary', () => {
it('parses a .bin file', async () => {
const name = 'argon_stroby.bin';
const data = await fs.readFile(path.join(PATH_FIXTURES_BINARIES_DIR, name));
const applicationBinary = { name, data };

const res = await binaryCommand._parseBinary(applicationBinary);

expect(path.basename(res.filename)).to.equal('argon_stroby.bin');
expect(res.crc.ok).to.equal(true);
expect(res).to.have.property('prefixInfo');
expect(res).to.have.property('suffixInfo');
});

it('errors if the binary is not valid', async () => {
const binary = { name: 'junk', data: Buffer.from('junk') };

let error;
try {
await binaryCommand._parseBinary(binary);
} catch (_error) {
error = _error;
}

expect(error).to.be.an.instanceof(Error);
expect(error.message).to.match(/Could not parse junk/);
});
});

describe('_verifyBundle', () => {
it('verifies bundle with asset info', async () => {
const zipPath = path.join(PATH_FIXTURES_THIRDPARTY_OTA_DIR, 'bundle.zip');
Expand Down

0 comments on commit 34a6359

Please sign in to comment.