Skip to content

Commit 90a72bf

Browse files
authored
chore: Update WebSocket server code from feedback (apache#14417)
1 parent a816655 commit 90a72bf

File tree

3 files changed

+69
-71
lines changed

3 files changed

+69
-71
lines changed

superset-websocket/spec/config.spec.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
});

superset-websocket/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ function applyEnvOverrides(config: ConfigType): ConfigType {
117117
STATSD_GLOBAL_TAGS: val => (config.statsd.globalTags = toStringArray(val)),
118118
};
119119

120-
for (const [envVar, set] of Object.entries(envVarConfigSetter)) {
120+
Object.entries(envVarConfigSetter).forEach(([envVar, set]) => {
121121
const envValue = process.env[envVar];
122122
if (envValue && isPresent(envValue)) {
123123
set(envValue);
124124
}
125-
}
125+
});
126126

127127
return config;
128128
}

0 commit comments

Comments
 (0)