|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const test = require('ava') |
| 4 | + |
| 5 | +test('region is required', function (t) { |
| 6 | + const error = t.throws(() => { |
| 7 | + getOptionsWithEnv() |
| 8 | + }, TypeError) |
| 9 | + |
| 10 | + t.is(error.message, 'region is required') |
| 11 | +}) |
| 12 | + |
| 13 | +test('host is required', function (t) { |
| 14 | + const error = t.throws(() => { |
| 15 | + getOptionsWithEnv({}, {region: 'foo'}) |
| 16 | + }, TypeError) |
| 17 | + |
| 18 | + t.is(error.message, 'host is required') |
| 19 | +}) |
| 20 | + |
| 21 | + |
| 22 | +test('region is taken from options if available', function (t) { |
| 23 | + const env = { |
| 24 | + AWS_REGION: 'aws_region', |
| 25 | + AWS_DDB_REGION: 'aws_ddb_region' |
| 26 | + } |
| 27 | + |
| 28 | + const options = getOptionsWithEnv(env, {region: 'option_region', host: 'foo'}) |
| 29 | + |
| 30 | + t.is(options.amazonES.region, 'option_region') |
| 31 | +}) |
| 32 | + |
| 33 | +test('region is taken from AWS_REGION by default', function (t) { |
| 34 | + const env = { |
| 35 | + AWS_REGION: 'aws_region' |
| 36 | + } |
| 37 | + |
| 38 | + const options = getOptionsWithEnv(env, {host: 'foo'}) |
| 39 | + |
| 40 | + t.is(options.amazonES.region, 'aws_region') |
| 41 | +}) |
| 42 | + |
| 43 | +test('region prefers envPrefix variable', function (t) { |
| 44 | + const env = { |
| 45 | + AWS_REGION: 'aws_region', |
| 46 | + AWS_DDB_REGION: 'aws_ddb_region' |
| 47 | + } |
| 48 | + |
| 49 | + const options = getOptionsWithEnv(env, {envPrefix: 'AWS_DDB', host: 'foo'}) |
| 50 | + |
| 51 | + t.is(options.amazonES.region, 'aws_ddb_region') |
| 52 | +}) |
| 53 | + |
| 54 | +test('connectionClass ignored in offline mode', function (t) { |
| 55 | + const env = { |
| 56 | + IS_OFFLINE: true |
| 57 | + } |
| 58 | + |
| 59 | + const options = getOptionsWithEnv(env, {region: 'foo', host: 'bar'}) |
| 60 | + |
| 61 | + t.falsy(options.connectionClass) |
| 62 | +}) |
| 63 | + |
| 64 | +test('connectionClass set by default', function (t) { |
| 65 | + const options = getOptionsWithEnv(null, {region: 'foo', host: 'bar'}) |
| 66 | + |
| 67 | + t.is(typeof (options.connectionClass), 'function') |
| 68 | +}) |
| 69 | + |
| 70 | + |
| 71 | +test('sets environment credentials by default', function (t) { |
| 72 | + const options = getOptionsWithEnv({}, {region: 'foo', host: 'bar'}) |
| 73 | + |
| 74 | + t.is(options.amazonES.credentials.constructor.name, 'EnvironmentCredentials') |
| 75 | +}) |
| 76 | + |
| 77 | +function getOptionsWithEnv (env, options) { |
| 78 | + process.env = env || {} |
| 79 | + options = options || {} |
| 80 | + |
| 81 | + return require('./index').getOptions(options) |
| 82 | +} |
0 commit comments