Skip to content

Commit de12c8b

Browse files
authored
Add Test To Verify NEW_RELIC_* Env Vars Not Reset During Upgrade (#159)
* Add Test To Verify NEW_RELIC_* Env Vars Not Reset During Upgrade Closes #158 * Only remove environment variables the CLI manages
1 parent 3ae77ee commit de12c8b

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

newrelic_lambda_cli/layers.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
from newrelic_lambda_cli.integrations import _get_license_key_policy_arn
1212
from newrelic_lambda_cli.types import LayerInstall, LayerUninstall
1313

14+
NEW_RELIC_ENV_VARS = (
15+
"NEW_RELIC_ACCOUNT_ID",
16+
"NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS",
17+
"NEW_RELIC_LAMBDA_EXTENSION_ENABLED",
18+
"NEW_RELIC_LAMBDA_HANDLER",
19+
"NEW_RELIC_LICENSE_KEY",
20+
"NEW_RELIC_LOG_ENDPOINT",
21+
"NEW_RELIC_TELEMETRY_ENDPOINT",
22+
)
23+
1424

1525
def index(region, runtime):
1626
req = requests.get(
@@ -120,14 +130,9 @@ def _add_new_relic(input, config, nr_license_key):
120130
"NEW_RELIC_LAMBDA_EXTENSION_ENABLED"
121131
] = "true"
122132

123-
if input.enable_extension_function_logs:
124-
update_kwargs["Environment"]["Variables"][
125-
"NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
126-
] = "true"
127-
else:
128-
update_kwargs["Environment"]["Variables"][
129-
"NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
130-
] = "false"
133+
update_kwargs["Environment"]["Variables"][
134+
"NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGS"
135+
] = ("true" if input.enable_extension_function_logs else "false")
131136

132137
if input.nr_region == "staging":
133138
update_kwargs["Environment"]["Variables"][
@@ -242,7 +247,7 @@ def _remove_new_relic(input, config):
242247
.get("Environment", {})
243248
.get("Variables", {})
244249
.items()
245-
if not key.startswith("NEW_RELIC")
250+
if key not in NEW_RELIC_ENV_VARS
246251
}
247252

248253
# Remove New Relic layers

tests/test_layers.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ def test_add_new_relic(aws_credentials, mock_function_config):
152152
in config["Configuration"]["Environment"]["Variables"]
153153
)
154154

155+
config = mock_function_config("python3.6")
156+
config["Configuration"]["Environment"]["Variables"]["NEW_RELIC_FOO"] = "bar"
157+
config["Configuration"]["Layers"] = [{"Arn": get_arn_prefix("us-east-1")}]
158+
update_kwargs = _add_new_relic(
159+
layer_install(
160+
session=session,
161+
aws_region="us-east-1",
162+
nr_account_id=12345,
163+
enable_extension=True,
164+
enable_extension_function_logs=True,
165+
upgrade=True,
166+
),
167+
config,
168+
"foobarbaz",
169+
)
170+
assert "NEW_RELIC_FOO" in update_kwargs["Environment"]["Variables"]
171+
assert update_kwargs["Layers"][0] != get_arn_prefix("us-east-1")
172+
155173

156174
@mock_lambda
157175
def test_remove_new_relic(aws_credentials, mock_function_config):

0 commit comments

Comments
 (0)