28
28
29
29
class TestLogRecord (unittest .TestCase ):
30
30
def test_log_record_to_json (self ):
31
- expected = json .dumps (
32
- {
33
- "body" : "a log line" ,
34
- "severity_number" : None ,
35
- "severity_text" : None ,
36
- "attributes" : {
37
- "mapping" : {"key" : "value" },
38
- "none" : None ,
39
- "sequence" : [1 , 2 ],
40
- "str" : "string" ,
41
- },
42
- "dropped_attributes" : 0 ,
43
- "timestamp" : "1970-01-01T00:00:00.000000Z" ,
44
- "observed_timestamp" : "1970-01-01T00:00:00.000000Z" ,
45
- "trace_id" : "" ,
46
- "span_id" : "" ,
47
- "trace_flags" : None ,
48
- "resource" : {
49
- "attributes" : {"service.name" : "foo" },
50
- "schema_url" : "" ,
51
- },
52
- },
53
- indent = 4 ,
54
- )
55
- actual = LogRecord (
31
+ log_record = LogRecord (
56
32
timestamp = 0 ,
57
33
observed_timestamp = 0 ,
58
- body = "a log line" ,
34
+ body = { "key" : "logLine" , "bytes" : b"123" } ,
59
35
resource = Resource ({"service.name" : "foo" }),
60
36
attributes = {
61
37
"mapping" : {"key" : "value" },
@@ -65,10 +41,9 @@ def test_log_record_to_json(self):
65
41
},
66
42
)
67
43
68
- self .assertEqual (expected , actual .to_json (indent = 4 ))
69
44
self .assertEqual (
70
- actual .to_json (indent = None ),
71
- '{"body": "a log line" , "severity_number": null, "severity_text": null, "attributes": {"mapping": {"key": "value"}, "none": null, "sequence": [1, 2], "str": "string"}, "dropped_attributes": 0, "timestamp": "1970-01-01T00:00:00.000000Z", "observed_timestamp": "1970-01-01T00:00:00.000000Z", "trace_id": "", "span_id": "", "trace_flags": null, "resource": {"attributes": {"service.name": "foo"}, "schema_url": ""}}' ,
45
+ log_record .to_json (indent = None ),
46
+ '{"body": {"key": "logLine", "bytes": "MTIz"} , "severity_number": null, "severity_text": null, "attributes": {"mapping": {"key": "value"}, "none": null, "sequence": [1, 2], "str": "string"}, "dropped_attributes": 0, "timestamp": "1970-01-01T00:00:00.000000Z", "observed_timestamp": "1970-01-01T00:00:00.000000Z", "trace_id": "", "span_id": "", "trace_flags": null, "resource": {"attributes": {"service.name": "foo"}, "schema_url": ""}}' ,
72
47
)
73
48
74
49
def test_log_record_to_json_serializes_severity_number_as_int (self ):
0 commit comments