Skip to content

Commit 833605b

Browse files
authored
fix(ignore): add test to specifically check HA envs (#27969)
1 parent f4d821d commit 833605b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/settings.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,43 @@ describe("Settings", () => {
165165
writeAndCheck();
166166
});
167167

168+
it("Should apply Home Assistant environment variables", () => {
169+
// should be kept in sync with envs in https://github.com/zigbee2mqtt/hassio-zigbee2mqtt/blob/master/common/rootfs/docker-entrypoint.sh
170+
process.env.ZIGBEE2MQTT_CONFIG_FRONTEND_ENABLED = "true";
171+
process.env.ZIGBEE2MQTT_CONFIG_FRONTEND_PORT = "8099";
172+
process.env.ZIGBEE2MQTT_CONFIG_HOMEASSISTANT_ENABLED = "true";
173+
process.env.ZIGBEE2MQTT_CONFIG_SERIAL_PORT =
174+
"/dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_48be7a7468d8ed11bfea786ff2c613ac-if00-port0";
175+
process.env.ZIGBEE2MQTT_CONFIG_MQTT_SERVER = "mqtt://core-mosquitto:1883";
176+
process.env.ZIGBEE2MQTT_CONFIG_MQTT_USER = "addons";
177+
process.env.ZIGBEE2MQTT_CONFIG_MQTT_PASSWORD = "7RbR4NBSskS8TKG4ugzdRilXw6TPQ4NKFs259j2DxeultOFtl5JwciNZFd6feT5o";
178+
179+
write(configurationFile, {});
180+
181+
// @ts-expect-error workaround
182+
const expected = objectAssignDeep.noMutate({}, settings.testing.defaults);
183+
expected.frontend.enabled = true;
184+
expected.frontend.port = 8099;
185+
expected.homeassistant.enabled = true;
186+
expected.serial.port = "/dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_48be7a7468d8ed11bfea786ff2c613ac-if00-port0";
187+
expected.mqtt.server = "mqtt://core-mosquitto:1883";
188+
expected.mqtt.user = "addons";
189+
expected.mqtt.password = "7RbR4NBSskS8TKG4ugzdRilXw6TPQ4NKFs259j2DxeultOFtl5JwciNZFd6feT5o";
190+
expected.devices = {};
191+
expected.groups = {};
192+
193+
const writeAndCheck = (): void => {
194+
expect(settings.write()); // trigger writing of ENVs
195+
expect(settings.validate()).toStrictEqual([]);
196+
expect(settings.get()).toStrictEqual(expected);
197+
};
198+
199+
// Write trice to ensure there are no side effects.
200+
writeAndCheck();
201+
writeAndCheck();
202+
writeAndCheck();
203+
});
204+
168205
it("Should write environment variables as overrides to configuration.yaml, not in the ref file", () => {
169206
write(secretFile, {password: "password-in-secret-file"}, false);
170207
write(configurationFile, {mqtt: {password: "!secret password", server: "server"}});

0 commit comments

Comments
 (0)