-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_internal_test.go
More file actions
55 lines (45 loc) · 1.62 KB
/
error_internal_test.go
File metadata and controls
55 lines (45 loc) · 1.62 KB
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
// SPDX-License-Identifier: EUPL-1.2
package core
func TestError_ErrorLog_logger_Good(t *T) {
log := NewLog(LogOptions{Level: LevelDebug, Output: NewBuffer()})
AssertSame(t, log, (&ErrorLog{log: log}).logger())
}
func TestError_ErrorLog_logger_Bad(t *T) {
AssertSame(t, Default(), (&ErrorLog{}).logger())
}
func TestError_ErrorLog_logger_Ugly(t *T) {
original := Default()
defer SetDefault(original)
log := NewLog(LogOptions{Level: LevelQuiet, Output: NewBuffer()})
SetDefault(log)
AssertSame(t, log, (&ErrorLog{}).logger())
}
func TestError_ErrorPanic_appendReport_Good(t *T) {
handler := &ErrorPanic{filePath: Path(t.TempDir(), "crash.json")}
handler.appendReport(ax7CrashReport("panic: agent failed"))
r := handler.Reports(0)
RequireTrue(t, r.OK)
reports := r.Value.([]CrashReport)
AssertLen(t, reports, 1)
AssertEqual(t, "panic: agent failed", reports[0].Error)
}
func TestError_ErrorPanic_appendReport_Bad(t *T) {
path := Path(t.TempDir(), "crash.json")
RequireTrue(t, WriteFile(path, []byte("{"), 0o600).OK)
handler := &ErrorPanic{filePath: path}
handler.appendReport(ax7CrashReport("panic: recovered"))
r := handler.Reports(0)
RequireTrue(t, r.OK)
reports := r.Value.([]CrashReport)
AssertLen(t, reports, 1)
AssertEqual(t, "panic: recovered", reports[0].Error)
}
func TestError_ErrorPanic_appendReport_Ugly(t *T) {
handler := &ErrorPanic{filePath: Path(t.TempDir(), "nested", "crash.json")}
handler.appendReport(ax7CrashReport("panic: nested path"))
r := handler.Reports(0)
RequireTrue(t, r.OK)
reports := r.Value.([]CrashReport)
AssertLen(t, reports, 1)
AssertEqual(t, "panic: nested path", reports[0].Error)
}