|
| 1 | +/* |
| 2 | + * Copyright 2018 Expedia Group |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the License); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an AS IS BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | +const {expect} = require('chai'); |
| 19 | +const override = require('../../../server/config/override'); |
| 20 | + |
| 21 | +describe('override configuration reader', () => { |
| 22 | + it('iterates over environment variables and returns an empty object if no matching variable is found', () => { |
| 23 | + const envVariables = { |
| 24 | + rvm_bin_path: '/Users/mchandramouli/.rvm/bin', |
| 25 | + GEM_HOME: '/Users/mchandramouli/.rvm/gems/ruby-2.6.0', |
| 26 | + NVM_CD_FLAGS: '', |
| 27 | + TERM: 'xterm-256color' |
| 28 | + }; |
| 29 | + |
| 30 | + const actual = override.readOverrides(envVariables); |
| 31 | + expect(actual).to.deep.equal({}); |
| 32 | + }); |
| 33 | + |
| 34 | + it('iterates over environment variables and returns an object split by _', () => { |
| 35 | + const envVariables = { |
| 36 | + HAYSTACK_CONNECTORS_TRACES_ENABLED: 'true', |
| 37 | + HAYSTACK_CONNECTORS_TRACES_PROVIDER: 'haystack', |
| 38 | + TERM: 'xterm-256color' |
| 39 | + }; |
| 40 | + |
| 41 | + const actual = override.readOverrides(envVariables); |
| 42 | + expect(actual).to.deep.equal({ |
| 43 | + connectors: { |
| 44 | + traces: { |
| 45 | + enabled: 'true', |
| 46 | + provider: 'haystack' |
| 47 | + } |
| 48 | + } |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + it('iterates over environment variables and returns an object split by _ and camelCase words split by __', () => { |
| 53 | + const envVariables = { |
| 54 | + HAYSTACK_CONNECTORS_TRENDS_CONNECTOR__NAME: 'haystack', |
| 55 | + HAYSTACK_CONNECTORS_TRENDS_METRIC__TANK__URL: 'http://localhost:6000', |
| 56 | + TERM: 'xterm-256color' |
| 57 | + }; |
| 58 | + |
| 59 | + const actual = override.readOverrides(envVariables); |
| 60 | + expect(actual).to.deep.equal({ |
| 61 | + connectors: { |
| 62 | + trends: { |
| 63 | + connectorName: 'haystack', |
| 64 | + metricTankUrl: 'http://localhost:6000' |
| 65 | + } |
| 66 | + } |
| 67 | + }); |
| 68 | + }); |
| 69 | +}); |
0 commit comments