Skip to content

Commit 2053143

Browse files
committed
Update assertions to check payload types.
1 parent 8cc6e57 commit 2053143

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

tests/agent_features/test_serverless_mode.py

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import json
1516
import pytest
1617

1718
from newrelic.api.application import application_instance
@@ -69,6 +70,9 @@ def _test():
6970
# Validate that something is printed to stdout
7071
assert out
7172

73+
# Verify that the payload is loadable JSON
74+
payload = json.loads(out)
75+
7276

7377
def test_no_cat_headers(serverless_application):
7478
@background_task(

tests/agent_unittests/test_agent_protocol.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def test_serverless_protocol_finalize(capsys):
532532
assert payload[:2] == [1, "NR_LAMBDA_MONITORING"]
533533

534534
data = serverless_payload_decode(payload[2])
535-
assert data["data"] == {"metric_data": "[1,2,3]"}
535+
assert data["data"] == {"metric_data": [1,2,3]}
536536

537537
assert data["metadata"]["foo"] == "bar"
538538
assert data["metadata"]["agent_version"] != "x"

tests/agent_unittests/test_http_client.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -542,24 +542,24 @@ def test_serverless_mode_client():
542542
for method in methods:
543543
params = {"method": method}
544544
status, data = client.send_request(
545-
params=params, payload=method.encode("utf-8")
545+
params=params, payload=json.dumps({"method": method}).encode("utf-8"),
546546
)
547547

548548
assert status == 200
549549
assert json.loads(data.decode("utf-8"))
550550

551551
# Verify that missing methods aren't captured
552-
status, _ = client.send_request(payload=b"*")
552+
status, _ = client.send_request(payload=b"{}")
553553
assert status == 400
554554

555555
# Verify that invalid methods aren't captured
556-
status, _ = client.send_request(params={"method": "foo"}, payload=b"*")
556+
status, _ = client.send_request(params={"method": "foo"}, payload=b"{}")
557557
assert status == 400
558558

559559
payloads = client.finalize()
560560
assert len(payloads) == len(methods)
561561
for method in methods:
562-
assert payloads[method] == method.encode("utf-8")
562+
assert payloads[method] == {"method": method}
563563

564564

565565
@pytest.mark.parametrize(

tests/testing_support/validators/validate_serverless_data.py

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
1516
from newrelic.common.object_wrapper import (
1617
transient_function_wrapper,
1718
function_wrapper)
@@ -40,6 +41,9 @@ def _validate():
4041
for method in expected_methods:
4142
assert method in payload
4243

44+
# Verify the method is not a byte string
45+
assert isinstance(payload[method], (dict, list))
46+
4347
for method in forgone_methods:
4448
assert method not in payload
4549

0 commit comments

Comments
 (0)