Skip MQTT allocation when disabled (#10411)
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
co-authored by
GitHub
Ben Meadors
parent
784e3748e2
commit
4553d1e0b1
@@ -409,6 +409,9 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length)
|
||||
|
||||
void mqttInit()
|
||||
{
|
||||
if (!moduleConfig.mqtt.enabled)
|
||||
return;
|
||||
|
||||
new MQTT();
|
||||
}
|
||||
|
||||
|
||||
@@ -800,6 +800,17 @@ void test_disabled(void)
|
||||
TEST_ASSERT_FALSE(mqtt->isEnabled());
|
||||
}
|
||||
|
||||
void test_mqttInitSkipsAllocationWhenDisabled(void)
|
||||
{
|
||||
delete unitTest;
|
||||
mqtt = unitTest = NULL;
|
||||
|
||||
moduleConfig.mqtt.enabled = false;
|
||||
mqttInit();
|
||||
|
||||
TEST_ASSERT_NULL(mqtt);
|
||||
}
|
||||
|
||||
// Subscriptions contain the moduleConfig.mqtt.root prefix.
|
||||
void test_customMqttRoot(void)
|
||||
{
|
||||
@@ -912,6 +923,7 @@ void setup()
|
||||
RUN_TEST(test_usingCustomServer);
|
||||
RUN_TEST(test_enabled);
|
||||
RUN_TEST(test_disabled);
|
||||
RUN_TEST(test_mqttInitSkipsAllocationWhenDisabled);
|
||||
RUN_TEST(test_customMqttRoot);
|
||||
RUN_TEST(test_configEmptyIsValid);
|
||||
RUN_TEST(test_configEnabledEmptyIsValid);
|
||||
|
||||
Reference in New Issue
Block a user