-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.test.js
82 lines (57 loc) · 1.9 KB
/
index.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
'use strict'
const test = require('ava')
test('region is required', function (t) {
const error = t.throws(() => {
getOptionsWithEnv()
}, TypeError)
t.is(error.message, 'region is required')
})
test('host is required', function (t) {
const error = t.throws(() => {
getOptionsWithEnv({}, {region: 'foo'})
}, TypeError)
t.is(error.message, 'host is required')
})
test('region is taken from options if available', function (t) {
const env = {
AWS_REGION: 'aws_region',
AWS_DDB_REGION: 'aws_ddb_region'
}
const options = getOptionsWithEnv(env, {region: 'option_region', host: 'foo'})
t.is(options.amazonES.region, 'option_region')
})
test('region is taken from AWS_REGION by default', function (t) {
const env = {
AWS_REGION: 'aws_region'
}
const options = getOptionsWithEnv(env, {host: 'foo'})
t.is(options.amazonES.region, 'aws_region')
})
test('region prefers envPrefix variable', function (t) {
const env = {
AWS_REGION: 'aws_region',
AWS_DDB_REGION: 'aws_ddb_region'
}
const options = getOptionsWithEnv(env, {envPrefix: 'AWS_DDB', host: 'foo'})
t.is(options.amazonES.region, 'aws_ddb_region')
})
test('connectionClass ignored in offline mode', function (t) {
const env = {
IS_OFFLINE: true
}
const options = getOptionsWithEnv(env, {region: 'foo', host: 'bar'})
t.falsy(options.connectionClass)
})
test('connectionClass set by default', function (t) {
const options = getOptionsWithEnv(null, {region: 'foo', host: 'bar'})
t.is(typeof (options.connectionClass), 'function')
})
test('sets environment credentials by default', function (t) {
const options = getOptionsWithEnv({}, {region: 'foo', host: 'bar'})
t.is(options.amazonES.credentials.constructor.name, 'EnvironmentCredentials')
})
function getOptionsWithEnv (env, options) {
process.env = env || {}
options = options || {}
return require('./index').getOptions(options)
}