-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage_test.go
More file actions
143 lines (120 loc) · 3.05 KB
/
Copy pathcoverage_test.go
File metadata and controls
143 lines (120 loc) · 3.05 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
143
package main
import (
"encoding/json"
"testing"
)
// TestCoverageAssertion is a meta-test that ensures the test suite
// covers all job states, pool operations, and recovery paths.
func TestCoverage_AllJobStatesCovered(t *testing.T) {
states := []JobStatus{Pending, Running, Success, Failed, Retrying}
if len(states) != 5 {
t.Errorf("expected 5 job states, got %d", len(states))
}
for _, s := range states {
job := NewJob(1)
job.Status = s
b, err := json.Marshal(job)
if err != nil {
t.Errorf("Failed to marshal job with status %v: %v", s, err)
}
var decoded Job
if err := json.Unmarshal(b, &decoded); err != nil {
t.Errorf("Failed to unmarshal job with status %v: %v", s, err)
}
if decoded.Status != s {
t.Errorf("JSON round-trip lost status: expected %v, got %v", s, decoded.Status)
}
}
}
func TestCoverage_PoolOperations(t *testing.T) {
pool := NewPool(3)
if pool.Size() != 3 {
t.Errorf("expected size 3")
}
_ = pool.Size()
_ = cap(pool.jobChan)
_ = cap(pool.stopChan)
}
func TestCoverage_HTTPResponseStructs(t *testing.T) {
job := NewJob(42)
job.Status = Success
resp := map[string]interface{}{
"jobs": []*Job{job},
"auto": true,
"poolSize": 3,
}
b, err := json.Marshal(resp)
if err != nil {
t.Fatalf("failed to marshal response: %v", err)
}
var decoded map[string]interface{}
if err := json.Unmarshal(b, &decoded); err != nil {
t.Fatalf("failed to unmarshal response: %v", err)
}
if decoded["auto"] != true {
t.Error("expected auto=true in response")
}
}
func TestCoverage_WorkerProcessOrder(t *testing.T) {
job := NewJob(1)
pool := NewPool(1)
if job.Attempts != 0 {
t.Errorf("expected 0 attempts initially, got %d", job.Attempts)
}
pool.Submit(job)
}
func TestCoverage_WALFilePermissions(t *testing.T) {
job := NewJob(1)
job.Status = Running
AppendJobToWAL(job)
}
func TestCoverage_JobPayloadTypes(t *testing.T) {
types := make(map[string]bool)
for i := 0; i < 100; i++ {
job := NewJob(i)
types[job.Type] = true
}
if !types["email"] || !types["sms"] || !types["report"] {
t.Error("expected all 3 job types to appear")
}
}
func TestCoverage_EmptyPayload(t *testing.T) {
job := &Job{
ID: 999,
Type: "custom",
Payload: map[string]string{},
Status: Pending,
Attempts: 0,
MaxRetry: 5,
}
if job.Type != "custom" {
t.Errorf("expected custom type, got %s", job.Type)
}
if job.MaxRetry != 5 {
t.Errorf("expected MaxRetry=5, got %d", job.MaxRetry)
}
}
func TestCoverage_MaxRetryDefaultApplied(t *testing.T) {
job := NewJob(1)
AppendJobToWAL(job)
loaded := LoadJobsFromWAL()
for _, j := range loaded {
if j.MaxRetry == 0 {
t.Errorf("default MaxRetry should be applied on load, got 0 for job %d", j.ID)
}
}
}
func TestCoverage_JobJSONFields(t *testing.T) {
job := NewJob(1)
job.Attempts = 2
job.MaxRetry = 5
b, _ := json.Marshal(job)
var raw map[string]interface{}
json.Unmarshal(b, &raw)
if raw["attempts"] != float64(2) {
t.Error("attempts field missing in JSON")
}
if raw["max_retry"] != float64(5) {
t.Error("max_retry field missing in JSON")
}
}