Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielrindlaub committed Aug 8, 2024
1 parent d8d3d4b commit 94f0e7c
Show file tree
Hide file tree
Showing 4 changed files with 542 additions and 496 deletions.
228 changes: 116 additions & 112 deletions ingest-delete/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,131 +6,135 @@ import { MockAgent, setGlobalDispatcher } from 'undici';
import SSM from '@aws-sdk/client-ssm';

test('Basic - CloudWatch Alarm', async (t) => {
const mockAgent = new MockAgent();
setGlobalDispatcher(mockAgent);

const mockPool = mockAgent.get('http://example.com');

mockPool.intercept({
path: '/',
method: 'POST'
}).reply(200, { message: 'posted' });

const order = [];
Sinon.stub(SSM.SSMClient.prototype, 'send').callsFake((command) => {
if (command instanceof SSM.GetParametersCommand) {
order.push('SSM:GetParametersCommand');

t.deepEquals(command.input, {
Names: ['/api/url-test'],
WithDecryption: true
});

return Promise.resolve({
Parameters: [{
Name: '/api/url-test',
Value: 'http://example.com'
}]
});
} else {
t.fail('Unexpected Command');
}
});

Sinon.stub(CloudFormation.CloudFormationClient.prototype, 'send').callsFake((command) => {
if (command instanceof CloudFormation.DeleteStackCommand) {
order.push('CloudFormation:DeleteStack');
const mockAgent = new MockAgent();
setGlobalDispatcher(mockAgent);

const mockPool = mockAgent.get('http://example.com');

mockPool
.intercept({
path: '/',
method: 'POST',
})
.reply(200, { message: 'posted' });

const order = [];
Sinon.stub(SSM.SSMClient.prototype, 'send').callsFake((command) => {
if (command instanceof SSM.GetParametersCommand) {
order.push('SSM:GetParametersCommand');

t.deepEquals(command.input, {
Names: ['/api/url-test'],
WithDecryption: true,
});

return Promise.resolve({
Parameters: [
{
Name: '/api/url-test',
Value: 'http://example.com',
},
],
});
} else {
t.fail('Unexpected Command');
}
});

t.ok(command.input.StackName.startsWith('test-stack-batch'));
Sinon.stub(CloudFormation.CloudFormationClient.prototype, 'send').callsFake((command) => {
if (command instanceof CloudFormation.DeleteStackCommand) {
order.push('CloudFormation:DeleteStack');

return Promise.resolve({});
} else {
t.fail('Unexpected Command');
}
});
t.ok(command.input.StackName.startsWith('test-stack-batch'));

try {
process.env.STAGE = 'test';
await IngestDelete({
Records: [{
Sns: {
Message: JSON.stringify({
AlarmName: 'test-stack-batch-847400c8-8e54-4a40-ab5c-0d593939c883-sqs-empty'
})
}
}]
});
} catch (err) {
t.error(err);
return Promise.resolve({});
} else {
t.fail('Unexpected Command');
}
});

try {
process.env.STAGE = 'test';
await IngestDelete({
Records: [
{
Sns: {
Message: JSON.stringify({
AlarmName: 'test-stack-batch-847400c8-8e54-4a40-ab5c-0d593939c883-sqs-empty',
}),
},
},
],
});
} catch (err) {
t.error(err);
}

t.deepEquals(order, [
'SSM:GetParametersCommand',
'CloudFormation:DeleteStack'
]);
t.deepEquals(order, ['SSM:GetParametersCommand', 'CloudFormation:DeleteStack']);

Sinon.restore();
t.end();
Sinon.restore();
t.end();
});

test('Basic - StopBatch API', async (t) => {
const mockAgent = new MockAgent();
setGlobalDispatcher(mockAgent);

const mockPool = mockAgent.get('http://example.com');

mockPool.intercept({
path: '/',
method: 'POST'
}).reply(200, { message: 'posted' });

const order = [];
Sinon.stub(SSM.SSMClient.prototype, 'send').callsFake((command) => {
if (command instanceof SSM.GetParametersCommand) {
order.push('SSM:GetParametersCommand');

t.deepEquals(command.input, {
Names: ['/api/url-test'],
WithDecryption: true
});

return Promise.resolve({
Parameters: [{
Name: '/api/url-test',
Value: 'http://example.com'
}]
});
} else {
t.fail('Unexpected Command');
}
});

Sinon.stub(CloudFormation.CloudFormationClient.prototype, 'send').callsFake((command) => {
if (command instanceof CloudFormation.DeleteStackCommand) {
order.push('CloudFormation:DeleteStack');
const mockAgent = new MockAgent();
setGlobalDispatcher(mockAgent);

const mockPool = mockAgent.get('http://example.com');

mockPool
.intercept({
path: '/',
method: 'POST',
})
.reply(200, { message: 'posted' });

const order = [];
Sinon.stub(SSM.SSMClient.prototype, 'send').callsFake((command) => {
if (command instanceof SSM.GetParametersCommand) {
order.push('SSM:GetParametersCommand');

t.deepEquals(command.input, {
Names: ['/api/url-test'],
WithDecryption: true,
});

return Promise.resolve({
Parameters: [
{
Name: '/api/url-test',
Value: 'http://example.com',
},
],
});
} else {
t.fail('Unexpected Command');
}
});

t.ok(command.input.StackName.startsWith('animl-ingest-test-batch-'));
Sinon.stub(CloudFormation.CloudFormationClient.prototype, 'send').callsFake((command) => {
if (command instanceof CloudFormation.DeleteStackCommand) {
order.push('CloudFormation:DeleteStack');

return Promise.resolve({});
} else {
t.fail('Unexpected Command');
}
});
t.ok(command.input.StackName.startsWith('animl-ingest-test-batch-'));

try {
process.env.STAGE = 'test';
await IngestDelete({
batch: 'batch-847400c8-8e54-4a40-ab5c-0d593939c883'
});
} catch (err) {
t.error(err);
return Promise.resolve({});
} else {
t.fail('Unexpected Command');
}
});

try {
process.env.STAGE = 'test';
await IngestDelete({
batch: 'batch-847400c8-8e54-4a40-ab5c-0d593939c883',
});
} catch (err) {
t.error(err);
}

t.deepEquals(order, [
'SSM:GetParametersCommand',
'CloudFormation:DeleteStack'
]);
t.deepEquals(order, ['SSM:GetParametersCommand', 'CloudFormation:DeleteStack']);

Sinon.restore();
t.end();
Sinon.restore();
t.end();
});
Loading

0 comments on commit 94f0e7c

Please sign in to comment.