39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package workflow
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestClipTailKeepsFailures(t *testing.T) {
|
|
passing := strings.Repeat("ok \tgithub.com/x/pkg\t0.010s\n", 200)
|
|
tests := []struct {
|
|
name, out string
|
|
want []string
|
|
}{
|
|
{
|
|
name: "a failing test early in long output",
|
|
out: "--- FAIL: TestHostLaunch (0.25s)\n runner_test.go:191: operation not permitted\n" + passing + "task: Failed to run task \"lint\": exit status 1\n",
|
|
want: []string{"--- FAIL: TestHostLaunch", "runner_test.go:191:", "exit status 1"},
|
|
},
|
|
{
|
|
name: "a lint finding early in long output",
|
|
out: "internal/a/b.go:17:21: os/exec.Command must not be called (noctx)\n" + passing + "1 issues:\n",
|
|
want: []string{"b.go:17:21: os/exec.Command", "1 issues:"},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := clipTail(tt.out, 2048)
|
|
if len(got) > 2048+len("…(truncated)\n") {
|
|
t.Fatalf("clipped to %d bytes, want at most 2048 plus the marker", len(got))
|
|
}
|
|
for _, w := range tt.want {
|
|
if !strings.Contains(got, w) {
|
|
t.Errorf("clipped output lacks %q:\n%s", w, got)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|