UNPKG

3.6 kBJavaScriptView Raw
1const StackOutputs = require('../functions/stack-outputs');
2const test = require('tape');
3const AWS = require('@mapbox/mock-aws-sdk-js');
4const http = require('http');
5
6test('[stack-outputs] create handles errors', assert => {
7 AWS.stub('CloudFormation', 'describeStacks', (opts, cb) => {
8 assert.deepEquals(opts, {
9 StackName: 'StackName'
10 }, 'describeStacks params');
11 return cb(new Error('random error'));
12 });
13
14 const stackoutputs = new StackOutputs('StackName', 'us-east-1');
15
16 stackoutputs.create((err) => {
17 assert.equals(err.message, 'random error', 'errors');
18 AWS.CloudFormation.restore();
19 assert.end();
20 });
21});
22
23test('[stack-outputs] create handles success', assert => {
24 const describeStacks = AWS.stub('CloudFormation', 'describeStacks', (opts, cb) => {
25 assert.deepEquals(opts, {
26 StackName: 'StackName'
27 }, 'describeStacks params');
28 return cb(null, { Stacks: [ { Outputs: [{ OutputKey: 'First', OutputValue: 'first output' }, { OutputKey: 'Second', OutputValue: 'second output'}] }] });
29 });
30
31 const stackoutputs = new StackOutputs('StackName', 'us-east-1');
32
33 stackoutputs.create((err, res) => {
34 assert.ifError(err, 'should not error');
35 assert.ok(describeStacks.callCount === 1, 'describeStacks called');
36 assert.deepEqual(res, { First: 'first output', Second: 'second output' }, 'response has output key and output value');
37 AWS.CloudFormation.restore();
38 assert.end();
39 });
40});
41
42test('[stack-outputs] update does the same thing as create', assert => {
43 AWS.stub('CloudFormation', 'describeStacks', (opts, cb) => {
44 assert.deepEquals(opts, {
45 StackName: 'StackName'
46 }, 'describeStacks params');
47 return cb(null, { Stacks: [ { Outputs: [{ OutputKey: 'First', OutputValue: 'first output' }, { OutputKey: 'Second', OutputValue: 'second output'}] }] });
48 });
49
50 const stackoutputs = new StackOutputs('StackName', 'us-east-1');
51
52 stackoutputs.update((err, res) => {
53 assert.ifError(err, 'should not error');
54 assert.deepEqual(res, { First: 'first output', Second: 'second output' }, 'response has output key and output value');
55 AWS.CloudFormation.restore();
56 assert.end();
57 });
58});
59
60test('[stack-outputs] delete does nothing', assert => {
61 const stackoutputs = new StackOutputs('StackName', 'us-east-1');
62
63 stackoutputs.delete(() => {
64 assert.end();
65 });
66});
67
68test('[stack-outputs] manage parses events and relays LatestStreamLabel through Response', assert => {
69 http.request = (options, cb) => {
70 return {
71 on: function() {
72 return this;
73 },
74 write: () => {},
75 end: () => {
76 return cb();
77 }
78 };
79 };
80
81 const describeStacks = AWS.stub('CloudFormation', 'describeStacks', (opts, cb) => {
82 assert.deepEquals(opts, {
83 StackName: 'Stack Name'
84 }, 'describeStacks params');
85 return cb(null, { Stacks: [ { Outputs: [{ OutputKey: 'First', OutputValue: 'first output' }, { OutputKey: 'Second', OutputValue: 'second output'}] }] });
86 });
87
88
89 StackOutputs.manage({
90 ResponseURL: 'http://api.mapbox.com/hello',
91 PhysicalResourceId: 'abc',
92 StackId: 'abc',
93 LogicalResourceId: 'abc',
94 ResourceProperties: {
95 StackName: 'Stack Name',
96 Region: 'us-east-1'
97 },
98 RequestId: 'abc',
99 RequestType: 'CREATE'
100 }, {
101 done: (err, body) => {
102 assert.ifError(err, 'no error');
103 assert.ok (describeStacks.callCount === 1, 'describeStacks called');
104 assert.equals(JSON.parse(body).Status, 'SUCCESS', 'status is success');
105 AWS.CloudFormation.restore();
106 assert.end();
107 }
108 });
109
110});