-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathgithub_actions_format_test.go
More file actions
142 lines (111 loc) · 4.02 KB
/
Copy pathgithub_actions_format_test.go
File metadata and controls
142 lines (111 loc) · 4.02 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package testjson
import (
"bufio"
"bytes"
"testing"
"gotest.tools/v3/assert"
)
func flushGitHubActionsBuffer(t *testing.T, buf *bufio.Writer, out *bytes.Buffer) string {
t.Helper()
assert.NilError(t, buf.Flush())
return out.String()
}
func TestWriteGitHubActionsError_FailureAnnotations(t *testing.T) {
out := new(bytes.Buffer)
writer := bufio.NewWriter(out)
event := TestEvent{Test: "pkg.TestFailure"}
lines := []string{"\tfailure_test.go:42: something went wrong"}
writeGitHubActionsError(writer, event, lines, newGitHubActionsErrorPatterns())
assert.Equal(t,
flushGitHubActionsBuffer(t, writer, out),
"::error file=failure_test.go,line=42,title=pkg.TestFailure::something went wrong\n",
)
}
func TestWriteGitHubActionsError_PanicPrefersTestFile(t *testing.T) {
out := new(bytes.Buffer)
writer := bufio.NewWriter(out)
event := TestEvent{Test: "pkg.TestPanics"}
lines := []string{
"panic: runtime error: index out of range",
"\t/usr/local/go/src/runtime/panic.go:88 +0x123",
"\t/home/user/project/example_test.go:45 +0x456",
"\t/home/user/project/example.go:12 +0x222",
}
writeGitHubActionsError(writer, event, lines, newGitHubActionsErrorPatterns())
assert.Equal(t,
flushGitHubActionsBuffer(t, writer, out),
"::error file=example_test.go,line=45,title=pkg.TestPanics::panic: runtime error: index out of range\n",
)
}
func TestWriteGitHubActionsError_PanicRequiresStrictMatch(t *testing.T) {
out := new(bytes.Buffer)
writer := bufio.NewWriter(out)
event := TestEvent{Test: "pkg.TestLogsPanicWord"}
lines := []string{"\tfailure_test.go:12: panic: not a real panic"}
writeGitHubActionsError(writer, event, lines, newGitHubActionsErrorPatterns())
assert.Equal(t,
flushGitHubActionsBuffer(t, writer, out),
"::error file=failure_test.go,line=12,title=pkg.TestLogsPanicWord::panic: not a real panic\n",
)
}
func TestWriteGitHubActionsError_IgnoresNonTestLogs(t *testing.T) {
out := new(bytes.Buffer)
writer := bufio.NewWriter(out)
event := TestEvent{Test: "pkg.TestWithTelemetry"}
lines := []string{
"\texample.go:140: [request-handler.log] 2025-12-04T17:55:24Z INFO Worker [RequestHandler] finished",
}
writeGitHubActionsError(writer, event, lines, newGitHubActionsErrorPatterns())
assert.Equal(t, flushGitHubActionsBuffer(t, writer, out), "")
}
func TestWriteGitHubActionsError_UsesAdditionalLinesForMessage(t *testing.T) {
out := new(bytes.Buffer)
writer := bufio.NewWriter(out)
event := TestEvent{Test: "pkg.TestHasDiff"}
lines := []string{
"\tmy_integration_test.go:42:",
"\t\tExpected",
"\t\t <int>: 0",
"\t\tto equal",
"\t\t <int>: 1",
"",
}
writeGitHubActionsError(writer, event, lines, newGitHubActionsErrorPatterns())
assert.Equal(t,
flushGitHubActionsBuffer(t, writer, out),
"::error file=my_integration_test.go,line=42,title=pkg.TestHasDiff::Expected <int>: 0 to equal <int>: 1\n",
)
}
func TestWriteGitHubActionsError_IncludesRepoRelativeFile(t *testing.T) {
patchPkgPathPrefix(t, "github.com/example/project")
out := new(bytes.Buffer)
writer := bufio.NewWriter(out)
event := TestEvent{
Test: "pkg.TestHasFailure",
Package: "github.com/example/project/internal/foo",
}
lines := []string{"\tfoo_test.go:12: boom"}
writeGitHubActionsError(writer, event, lines, newGitHubActionsErrorPatterns())
assert.Equal(t,
flushGitHubActionsBuffer(t, writer, out),
"::error file=internal/foo/foo_test.go,line=12,title=pkg.TestHasFailure::boom\n",
)
}
func TestWriteGitHubActionsError_PanicUsesRepoRelativeFile(t *testing.T) {
patchPkgPathPrefix(t, "github.com/example/project")
out := new(bytes.Buffer)
writer := bufio.NewWriter(out)
event := TestEvent{
Test: "pkg.TestPanicsHard",
Package: "github.com/example/project/pkg/bar",
}
lines := []string{
"panic: oh no",
"\t/home/runner/work/project/pkg/bar/bar_test.go:55 +0x123",
}
writeGitHubActionsError(writer, event, lines, newGitHubActionsErrorPatterns())
assert.Equal(t,
flushGitHubActionsBuffer(t, writer, out),
"::error file=pkg/bar/bar_test.go,line=55,title=pkg.TestPanicsHard::panic: oh no\n",
)
}