-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathintegration.test.js
141 lines (119 loc) · 3.39 KB
/
integration.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'use strict';
const { sleep, generateId, getCredentials, getServerlessSdk, getTable } = require('./utils');
// set enough timeout for deployment to finish
jest.setTimeout(30000);
const name = `aws-dynamodb-integration-tests-${generateId()}`;
// the yaml file we're testing against
const instanceYaml = {
org: 'serverlessinc',
app: 'myApp',
component: 'aws-dynamodb@dev',
name,
stage: 'dev',
inputs: {
deletionPolicy: 'delete',
timeToLiveSpecification: {
AttributeName: 'expires',
Enabled: true,
},
attributeDefinitions: [
{
AttributeName: 'attribute1',
AttributeType: 'S',
},
{
AttributeName: 'attribute2',
AttributeType: 'N',
},
],
keySchema: [
{
AttributeName: 'attribute1',
KeyType: 'HASH',
},
{
AttributeName: 'attribute2',
KeyType: 'RANGE',
},
], // local secondary indexes can only be added on table creation
localSecondaryIndexes: [
{
IndexName: 'myLocalSecondaryIndex',
Projection: {
ProjectionType: 'KEYS_ONLY',
},
KeySchema: [
{
AttributeName: 'attribute1',
KeyType: 'HASH',
},
{
AttributeName: 'attribute2',
KeyType: 'RANGE',
},
],
},
],
},
};
// get aws credentials from env
const credentials = getCredentials();
// get serverless access key from env and construct sdk
const sdk = getServerlessSdk(instanceYaml.org);
// clean up the instance after tests
afterAll(async () => {
await sdk.remove(instanceYaml, credentials);
});
it('should successfully deploy dynamodb table and local index', async () => {
const instance = await sdk.deploy(instanceYaml, credentials);
await sleep(5000);
const res = await getTable(credentials, name);
// const resTTL = await getTableTimeToLive(credentials, name);
expect(instance.outputs.name).toBeDefined();
expect(instance.outputs.arn).toBeDefined();
expect(res.Table.AttributeDefinitions.length).toEqual(2);
expect(res.Table.KeySchema.length).toEqual(2);
expect(res.Table.LocalSecondaryIndexes.length).toEqual(1);
});
// global secondary indexes take really long time to create.
// it causes the test to timeout and the remove operation to fail
// because another process is still in place
// as a result it
// it.skip('should successfully add global index', async () => {
// instanceYaml.inputs.globalSecondaryIndexes = [
// {
// IndexName: 'myGlobalSecondaryIndex',
// Projection: {
// ProjectionType: 'KEYS_ONLY'
// },
// KeySchema: [
// {
// AttributeName: 'attribute1',
// KeyType: 'HASH'
// },
// {
// AttributeName: 'attribute2',
// KeyType: 'RANGE'
// }
// ]
// }
// ]
// await sdk.deploy(instanceYaml, credentials)
// await sleep(5000)
// const res = await getTable(credentials, name)
// expect(res.Table.GlobalSecondaryIndexes.length).toEqual(1)
// })
it('should successfully remove dynamodb table', async () => {
await sdk.remove(instanceYaml, credentials);
await sleep(5000);
// make sure table was actually removed
let table;
try {
table = await getTable(credentials, name);
} catch (e) {
if (e.code !== 'ResourceNotFoundException') {
throw e;
}
}
expect(table).toBeUndefined();
});