forked from aiortc/aioquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_logger.py
58 lines (48 loc) · 1.67 KB
/
test_logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
import os
import tempfile
from unittest import TestCase
from aioquic.quic.logger import QuicFileLogger, QuicLogger
SINGLE_TRACE = {
"qlog_format": "JSON",
"qlog_version": "0.3",
"traces": [
{
"common_fields": {
"ODCID": "0000000000000000",
},
"events": [],
"vantage_point": {"name": "aioquic", "type": "client"},
}
],
}
class QuicLoggerTest(TestCase):
def test_empty(self):
logger = QuicLogger()
self.assertEqual(
logger.to_dict(),
{"qlog_format": "JSON", "qlog_version": "0.3", "traces": []},
)
def test_single_trace(self):
logger = QuicLogger()
trace = logger.start_trace(is_client=True, odcid=bytes(8))
logger.end_trace(trace)
self.assertEqual(logger.to_dict(), SINGLE_TRACE)
class QuicFileLoggerTest(TestCase):
def test_invalid_path(self):
with self.assertRaises(ValueError) as cm:
QuicFileLogger("this_path_should_not_exist")
self.assertEqual(
str(cm.exception),
"QUIC log output directory 'this_path_should_not_exist' does not exist",
)
def test_single_trace(self):
with tempfile.TemporaryDirectory() as dirpath:
logger = QuicFileLogger(dirpath)
trace = logger.start_trace(is_client=True, odcid=bytes(8))
logger.end_trace(trace)
filepath = os.path.join(dirpath, "0000000000000000.qlog")
self.assertTrue(os.path.exists(filepath))
with open(filepath, "r") as fp:
data = json.load(fp)
self.assertEqual(data, SINGLE_TRACE)