-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pytest for automated testing of the cpp sample. Signed-off-by: Mike Szczys <[email protected]>
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# CPP Test | ||
|
||
Compile an application in CPP and confirm it successfully connects to | ||
Golioth. | ||
|
||
See esp_idf/README.md for test requirements and commands to run the | ||
test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2024 Golioth, Inc. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
|
||
@pytest.fixture(scope='session') | ||
def anyio_backend(): | ||
return 'trio' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import logging | ||
import pytest | ||
from datetime import datetime, timezone | ||
import re | ||
|
||
pytestmark = pytest.mark.anyio | ||
|
||
async def test_hello(board, device): | ||
# Set Golioth credential | ||
golioth_cred = (await device.credentials.list())[0] | ||
await board.set_golioth_psk_credentials(golioth_cred.identity, golioth_cred.key) | ||
|
||
# Record timestamp and wait for fourth hello message | ||
start = datetime.now(timezone.utc) | ||
await board.wait_for_regex_in_line('.*Hello, Golioth 2!', timeout_s=90.0) | ||
|
||
# Check logs for hello messages | ||
end = datetime.now(timezone.utc) | ||
logs = await device.get_logs({'start': start.strftime('%Y-%m-%dT%H:%M:%S.%fZ'), 'end': end.strftime('%Y-%m-%dT%H:%M:%S.%fZ')}) | ||
|
||
# Test logs received from server | ||
r = re.compile(".*Hello, Golioth 1!") | ||
matching_log = list(filter(r.match, [str(l) for l in logs])) | ||
assert len(matching_log) == 1 |