Repository navigation
Expand file tree
/
Copy pathextract_failure_test.go
More file actions
79 lines (70 loc) · 1.92 KB
/
Copy pathextract_failure_test.go
File metadata and controls
79 lines (70 loc) · 1.92 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
// Root-level test (justified): exercises extractFirstFailure and writeGateLog — unexported functions used in cascade logic that do not expose external API points.
package devflow
import (
"os"
"path/filepath"
"testing"
)
func TestExtractFirstFailureNamesEveryFailingStage(t *testing.T) {
tests := []struct {
name string
output string
want string
}{
{
name: "single wasm failure",
output: "Tests failed: vet ✅, race ✅, tests ✅, wasm ❌ v0.0.56 (24.1s)",
want: "wasm",
},
{
name: "submodule wasm failure",
output: "Tests failed: vet ✅, race ✅, tests ✅, wasm tests ❌ (3s)",
want: "wasm tests",
},
{
name: "multiple failures",
output: "Tests failed: vet ❌, race ✅, tests ❌, wasm ✅ (3s)",
want: "vet, tests",
},
{
name: "timeout failure",
output: "Tests failed: timeout: TestX (exceeded 60s) ❌ (70s)",
want: "timeout: TestX (exceeded 60s)",
},
{
name: "go mod tidy failure fallback",
output: "go: updates to go.mod needed",
want: "failed",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := extractFirstFailure(tt.output)
if got != tt.want {
t.Errorf("extractFirstFailure(%q) = %q, want %q", tt.output, got, tt.want)
}
})
}
}
func TestWriteGateLog(t *testing.T) {
depName := "auth/tests"
content := "test output log content"
path := writeGateLog(depName, content)
if path == "" {
t.Fatal("expected writeGateLog to return a non-empty path")
}
t.Cleanup(func() {
os.Remove(path)
})
expectedFileName := "gopush-gate-auth-tests.log"
if filepath.Base(path) != expectedFileName {
t.Errorf("expected file base name %q, got %q", expectedFileName, filepath.Base(path))
}
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("failed to read created gate log file: %v", err)
}
if string(data) != content {
t.Errorf("expected file content %q, got %q", content, string(data))
}
}