|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +import { buildConfig } from '../src/config'; |
| 20 | + |
| 21 | +test('buildConfig() builds configuration and applies env var overrides', () => { |
| 22 | + let config = buildConfig(); |
| 23 | + |
| 24 | + expect(config.jwtSecret).toEqual( |
| 25 | + 'test123-test123-test123-test123-test123-test123-test123', |
| 26 | + ); |
| 27 | + expect(config.redis.host).toEqual('127.0.0.1'); |
| 28 | + expect(config.redis.port).toEqual(6379); |
| 29 | + expect(config.redis.password).toEqual(''); |
| 30 | + expect(config.redis.db).toEqual(10); |
| 31 | + expect(config.redis.ssl).toEqual(false); |
| 32 | + expect(config.statsd.host).toEqual('127.0.0.1'); |
| 33 | + expect(config.statsd.port).toEqual(8125); |
| 34 | + expect(config.statsd.globalTags).toEqual([]); |
| 35 | + |
| 36 | + process.env.JWT_SECRET = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; |
| 37 | + process.env.REDIS_HOST = '10.10.10.10'; |
| 38 | + process.env.REDIS_PORT = '6380'; |
| 39 | + process.env.REDIS_PASSWORD = 'admin'; |
| 40 | + process.env.REDIS_DB = '4'; |
| 41 | + process.env.REDIS_SSL = 'true'; |
| 42 | + process.env.STATSD_HOST = '15.15.15.15'; |
| 43 | + process.env.STATSD_PORT = '8000'; |
| 44 | + process.env.STATSD_GLOBAL_TAGS = 'tag-1,tag-2'; |
| 45 | + |
| 46 | + config = buildConfig(); |
| 47 | + |
| 48 | + expect(config.jwtSecret).toEqual('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'); |
| 49 | + expect(config.redis.host).toEqual('10.10.10.10'); |
| 50 | + expect(config.redis.port).toEqual(6380); |
| 51 | + expect(config.redis.password).toEqual('admin'); |
| 52 | + expect(config.redis.db).toEqual(4); |
| 53 | + expect(config.redis.ssl).toEqual(true); |
| 54 | + expect(config.statsd.host).toEqual('15.15.15.15'); |
| 55 | + expect(config.statsd.port).toEqual(8000); |
| 56 | + expect(config.statsd.globalTags).toEqual(['tag-1', 'tag-2']); |
| 57 | + |
| 58 | + delete process.env.JWT_SECRET; |
| 59 | + delete process.env.REDIS_HOST; |
| 60 | + delete process.env.REDIS_PORT; |
| 61 | + delete process.env.REDIS_PASSWORD; |
| 62 | + delete process.env.REDIS_DB; |
| 63 | + delete process.env.REDIS_SSL; |
| 64 | + delete process.env.STATSD_HOST; |
| 65 | + delete process.env.STATSD_PORT; |
| 66 | + delete process.env.STATSD_GLOBAL_TAGS; |
| 67 | +}); |
0 commit comments