Skip to content

Commit

Permalink
When packets are loaded, verify that they pass verifySeedPacket.
Browse files Browse the repository at this point in the history
This catches instances where seeds have a local seed reference that is incorrect.

Part of #39.
  • Loading branch information
jkomoros committed Jul 6, 2023
1 parent 6ff186e commit 345412d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from './environment.js';

import {
Seed, expandSeedPacket
Seed, expandSeedPacket, verifySeedPacket
} from './seed.js';

import {
Expand Down Expand Up @@ -167,6 +167,8 @@ export class Garden {
//Ensure seed packet is shaped properly
seedPacket.parse(packet);
const expandedPacket = expandSeedPacket(packet);
//This will throw if there are errors in the packet.
verifySeedPacket(expandedPacket);
if (!this._location) this._location = location;
for (const [id, seed] of Object.entries(expandedPacket.seeds)) {
const ref : AbsoluteSeedReference = {
Expand Down
23 changes: 23 additions & 0 deletions test/base/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EnvironmentData,
ExpandedSeedPacket,
SeedDataCompose,
SeedPacket,
SeedReference,
seedID,
seedPacket,
Expand Down Expand Up @@ -595,6 +596,28 @@ Suffix`;
assert.deepStrictEqual(result, golden);
});

it ('testing a packet with an invalid ref is caught', async () => {
const garden = loadTestGarden();
const packet : SeedPacket = {
'version': 0,
'seeds': {
'foo': {
'type': 'var',
'name': {
'id': 'bar-typo'
}
},
'bar': {
'type': 'log',
'value': 'hello, world'
}
}
};
assert.throws(() => {
garden.plantSeedPacket('test/base/c_test.json', packet);
});
});


});

Expand Down

0 comments on commit 345412d

Please sign in to comment.