Skip to content

Commit

Permalink
Improve publisher coverage & linting
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcasalboni committed May 20, 2024
1 parent 40c221b commit 6f001da
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
23 changes: 14 additions & 9 deletions lambda/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ module.exports.handler = async(event, context) => {
// publish version & assign alias (if present)
await utils.createPowerConfiguration(lambdaARN, currConfig.powerValue, currConfig.alias, currConfig.description);

// update iterator
const updatedIterator = {
index: (currentIterator.index + 1),
count: currentIterator.count,
continue: ((currentIterator.index + 1) < currentIterator.count),
};
return {
initConfigurations: ((updatedIterator.continue) ? lambdaConfigurations.initConfigurations : undefined),
iterator: updatedIterator,
const result = {
powerValues: lambdaConfigurations.powerValues,
initConfigurations: lambdaConfigurations.initConfigurations,
iterator: {
index: (currentIterator.index + 1),
count: currentIterator.count,
continue: ((currentIterator.index + 1) < currentIterator.count),
},
};

if (!result.iterator.continue) {
// clean the list of configuration if we're done iterating
delete result.initConfigurations;
}

return result;
};
function validateInputs(event) {
if (!event.lambdaARN) {
Expand Down
52 changes: 41 additions & 11 deletions test/unit/test-lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,23 +238,26 @@ describe('Lambda Functions', async() => {
{ },
{lambdaARN: 'arnOK'},
{lambdaARN: 'arnOK', lambdaConfigurations: {}},
{lambdaARN: 'arnOK',
{
lambdaARN: 'arnOK',
lambdaConfigurations: {
initConfigurations: [{
powerValue: 512,
alias: 'RAM512',
}],
},
},
{lambdaARN: 'arnOK',
{
lambdaARN: 'arnOK',
lambdaConfigurations: {
iterator: {
index: 1,
count: 1,
},
},
},
{lambdaARN: 'arnOK',
{
lambdaARN: 'arnOK',
lambdaConfigurations: {
initConfigurations: [{
powerValue: 512,
Expand All @@ -269,7 +272,8 @@ describe('Lambda Functions', async() => {
},
},
},
{lambdaARN: 'arnOK',
{
lambdaARN: 'arnOK',
lambdaConfigurations: {
initConfigurations: [{
powerValue: 512,
Expand All @@ -292,28 +296,54 @@ describe('Lambda Functions', async() => {
});
});

it('should publish the given lambda version', async() => {
it('should publish the given lambda version (first iteration)', async() => {
const generatedValues = await invokeForSuccess(handler, {
lambdaARN: 'arnOK',
lambdaConfigurations: {
initConfigurations: [{
powerValue: 512,
alias: 'RAM512',
}, {
powerValue: 1024,
alias: 'RAM1024',
}],
iterator: {
index: 0,
count: 2,
},
}});
expect(setLambdaPowerCounter).to.be(1);
expect(waitForFunctionUpdateCounter).to.be(1);
expect(publishLambdaVersionCounter).to.be(1);
expect(createLambdaAliasCounter).to.be(1);
expect(generatedValues.iterator.index).to.be(1); // index should be incremented by 1
expect(generatedValues.iterator.continue).to.be(true); // the iterator should be set to continue=false
expect(generatedValues.initConfigurations).to.be.a('array'); // initConfigurations should be a list
});

const aliasValue = 'RAM512';
const originalIndex = 0;
it('should publish the given lambda version (last iteration)', async() => {
const generatedValues = await invokeForSuccess(handler, {
lambdaARN: 'arnOK',
lambdaConfigurations: {
initConfigurations: [{
powerValue: 512,
alias: aliasValue,
alias: 'RAM512',
}, {
powerValue: 1024,
alias: 'RAM1024',
}],
iterator: {
index: originalIndex,
count: 1,
index: 1,
count: 2,
},
}});
expect(setLambdaPowerCounter).to.be(1);
expect(waitForFunctionUpdateCounter).to.be(1);
expect(publishLambdaVersionCounter).to.be(1);
expect(createLambdaAliasCounter).to.be(1);
expect(generatedValues.iterator.index).to.be(originalIndex + 1); // index should be incremented by 1
expect(generatedValues.iterator.index).to.be(2); // index should be incremented by 1
expect(generatedValues.iterator.continue).to.be(false); // the iterator should be set to continue=false
expect(generatedValues.initConfigurations).to.be(undefined); // initConfigurations should be unset
});

it('should publish the version even if an alias is not specified', async() => {
Expand Down

0 comments on commit 6f001da

Please sign in to comment.