Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('[template validation] defaults', async (assert) => {
const builtWithDefaults = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com'
}));
const tmp = path.join(os.tmpdir(), crypto.randomBytes(8).toString('hex'));
fs.writeFileSync(tmp, JSON.stringify(builtWithDefaults));
try {
await cf.validate(tmp);
assert.pass('template is valid');
} catch (err) {
assert.ifError(err, 'template is not valid');
}
test('[template]', () => {
assert.throws(
() => template(),
/options.service is required/,
'throws when missing required options'
);
const builtWithDefaults = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com'
}));
expect(builtWithDefaults).toMatchSnapshot('defaults');
const setsAllOptions = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
permissions: [
{
test('[template validation] options set', async (assert) => {
const setsAllOptions = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
permissions: [
{
Effect: 'Allow',
Action: 's3:GetObject',
Resource: 'arn:aws:s3:::bucket/*'
}
],
env: {
MyKey: 'MyValue'
},
prefix: 'Soup',
family: 'abc-123',
test('[template validation] fifo queue', async (assert) => {
const fifo = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com',
fifo: true
}));
const tmp = path.join(os.tmpdir(), crypto.randomBytes(8).toString('hex'));
fs.writeFileSync(tmp, JSON.stringify(fifo));
try {
await cf.validate(tmp);
assert.pass('template is valid');
} catch (err) {
assert.ifError(err, 'template is not valid');
expect(setsAllLowCPU).toMatchSnapshot('all-properties-low-CPU');
const fifo = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com',
fifo: true
}));
expect(fifo).toMatchSnapshot('fifo');
const fifoMaxSize = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com',
fifo: true,
maxSize: 50
}));
expect(fifoMaxSize).toMatchSnapshot('fifoMaxSize');
});
memory: 512,
softMemory: 128,
cpu: 0
},
privileged: true,
reduce: true,
messageTimeout: 300,
messageRetention: 1096,
deadletterThreshold: 50,
notificationEmail: 'hello@mapbox.pagerduty.com'
}));
expect(setsAllLowCPU).toMatchSnapshot('all-properties-low-CPU');
const fifo = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com',
fifo: true
}));
expect(fifo).toMatchSnapshot('fifo');
const fifoMaxSize = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com',
() => template(),
/options.service is required/,
'throws when missing required options'
);
const builtWithDefaults = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
notificationEmail: 'hello@mapbox.pagerduty.com'
}));
expect(builtWithDefaults).toMatchSnapshot('defaults');
const setsAllOptions = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
permissions: [
{
Effect: 'Allow',
Action: 's3:GetObject',
Resource: 'arn:aws:s3:::bucket/*'
}
],
env: {
MyKey: 'MyValue'
},
prefix: 'Soup',
family: 'abc-123',
memory: 512,
softMemory: 128,
cpu: cf.ref('Gitsha')
},
privileged: true,
reduce: true,
messageTimeout: 300,
messageRetention: 1096,
deadletterThreshold: 50,
deadletterAlarm: true,
notificationEmail: 'hello@mapbox.pagerduty.com'
}));
expect(setsAllOptions).toMatchSnapshot('all-properties');
const setsAllCPUNumber = cf.merge(template({
service: 'example',
serviceVersion: '1',
command: 'echo hello world',
cluster: 'processing',
permissions: [
{
Effect: 'Allow',
Action: 's3:GetObject',
Resource: 'arn:aws:s3:::bucket/*'
}
],
env: {
MyKey: 'MyValue'
},
prefix: 'Soup',
family: 'abc-123',
},
InputArtifacts: [
{ Name: 'Source' }
],
Configuration: {
ProjectName: cf.ref('AlpineBundler')
}
}
]
}
]
}
}
};
module.exports = cf.merge({ Parameters, Resources });
{ Name: 'FunctionName', Value: cf.ref('GatekeeperLambda') }
],
MetricName: 'Errors',
AlarmActions: [cf.ref('AlarmSNSTopic')]
}
}
};
const Outputs = {
GithubAppInstallationId: { Value: cf.ref('GithubAppInstallationId') },
GatekeeperLambda: { Value: cf.ref('GatekeeperLambda') }
};
const webhook = hookshot.github('TriggerLambda');
module.exports = cf.merge({ Parameters, Resources, Outputs }, webhook);