-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoScaling.test.js
57 lines (49 loc) · 1.8 KB
/
AutoScaling.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
const Test = require('thunk-test')
const assert = require('assert')
const AwsCredentials = require('./internal/AwsCredentials')
const AutoScaling = require('./AutoScaling')
const test = new Test('AutoScaling', async function () {
const awsCreds = await AwsCredentials('solum').catch(error => {
if (error.code == 'ENOENT') {
const accessKeyId = process.env.AWS_ACCESS_KEY_ID
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
if (accessKeyId == null || secretAccessKey == null) {
throw new Error('No AWS credential file or environment variables')
}
return { accessKeyId, secretAccessKey }
}
throw error
})
awsCreds.region = 'us-west-1'
const autoScaling = new AutoScaling({
...awsCreds,
})
// there is one auto scaling group named presidium-test with one ec2 instance in this region
{ // listInstances all instances
const response = await autoScaling.listAutoScalingGroups()
assert(
response.AutoScalingGroups.map(group => group.AutoScalingGroupName).includes('presidium-test'),
'There is no presidium-test autoscaling group, check the aws account'
)
assert.equal(response.NextToken, null)
}
{ // listAutoScalingGroups with tag
const response = await autoScaling.listAutoScalingGroups({
'tag:Env': 'test',
})
assert(
response.AutoScalingGroups.map(group => group.AutoScalingGroupName).includes('presidium-test'),
'There is no autoscaling group with tag:Env = test, check the aws account'
)
assert.equal(response.NextToken, null)
}
// setDesiredCapacity (errors if not auto scaling group not found)
await autoScaling.setDesiredCapacity({
autoScalingGroupName: 'presidium-test',
desiredCapacity: 0,
})
}).case()
if (process.argv[1] == __filename) {
test()
}
module.exports = test