Skip to content

Commit

Permalink
Update assertions to check payload types.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-feld committed Aug 24, 2020
1 parent 8cc6e57 commit 2053143
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions tests/agent_features/test_serverless_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import pytest

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

# Verify that the payload is loadable JSON
payload = json.loads(out)


def test_no_cat_headers(serverless_application):
@background_task(
Expand Down
2 changes: 1 addition & 1 deletion tests/agent_unittests/test_agent_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def test_serverless_protocol_finalize(capsys):
assert payload[:2] == [1, "NR_LAMBDA_MONITORING"]

data = serverless_payload_decode(payload[2])
assert data["data"] == {"metric_data": "[1,2,3]"}
assert data["data"] == {"metric_data": [1,2,3]}

assert data["metadata"]["foo"] == "bar"
assert data["metadata"]["agent_version"] != "x"
Expand Down
8 changes: 4 additions & 4 deletions tests/agent_unittests/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,24 +542,24 @@ def test_serverless_mode_client():
for method in methods:
params = {"method": method}
status, data = client.send_request(
params=params, payload=method.encode("utf-8")
params=params, payload=json.dumps({"method": method}).encode("utf-8"),
)

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

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

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

payloads = client.finalize()
assert len(payloads) == len(methods)
for method in methods:
assert payloads[method] == method.encode("utf-8")
assert payloads[method] == {"method": method}


@pytest.mark.parametrize(
Expand Down
4 changes: 4 additions & 0 deletions tests/testing_support/validators/validate_serverless_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.


from newrelic.common.object_wrapper import (
transient_function_wrapper,
function_wrapper)
Expand Down Expand Up @@ -40,6 +41,9 @@ def _validate():
for method in expected_methods:
assert method in payload

# Verify the method is not a byte string
assert isinstance(payload[method], (dict, list))

for method in forgone_methods:
assert method not in payload

Expand Down

0 comments on commit 2053143

Please sign in to comment.