From 402ce0322df97127190846e06235c3725481a871 Mon Sep 17 00:00:00 2001 From: David Kirov Date: Mon, 23 Dec 2024 12:52:43 +0200 Subject: [PATCH] Add unit tests for env var logic --- .../tests/base/checks/test_agent_check.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/datadog_checks_base/tests/base/checks/test_agent_check.py b/datadog_checks_base/tests/base/checks/test_agent_check.py index 2f77b049a389e6..f36bf041306f45 100644 --- a/datadog_checks_base/tests/base/checks/test_agent_check.py +++ b/datadog_checks_base/tests/base/checks/test_agent_check.py @@ -5,6 +5,7 @@ # Licensed under a 3-clause BSD style license (see LICENSE) import json import logging +import os from typing import Any # noqa: F401 import mock @@ -1293,3 +1294,21 @@ def test_detect_typos_configuration_models( assert "Detected potential typo in configuration option" not in caplog.text assert typos == set(unknown_options) + + +def test_env_var_logic_default(): + with mock.patch.dict('os.environ', {'GOFIPS': '0'}): + AgentCheck() + assert os.getenv('OPENSSL_CONF', None) is None + assert os.getenv('OPENSSL_MODULES', None) is None + + +def test_env_var_logic_preset(): + preset_conf = 'path/to/openssl.cnf' + preset_modules = 'path/to/ossl-modules' + with mock.patch.dict( + 'os.environ', {'GOFIPS': '1', 'OPENSSL_CONF': preset_conf, 'OPENSSL_MODULES': preset_modules} + ): + AgentCheck() + assert os.getenv('OPENSSL_CONF', None) == preset_conf + assert os.getenv('OPENSSL_MODULES', None) == preset_modules