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
|
package main
import (
"testing"
"time"
)
func TestExecRequestData_Validate(t *testing.T) {
tests := []struct {
name string
maxDurationMs int
wantErr error
}{
{"positive value", 1000, nil},
{"zero", 0, errInvalidMaxDuration},
{"negative value", -1, errInvalidMaxDuration},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := &execRequestData{MaxDurationMilliseconds: tt.maxDurationMs}
err := req.validate()
if err != tt.wantErr {
t.Errorf("validate() = %v, want %v", err, tt.wantErr)
}
})
}
}
func TestExecRequestData_MaxDuration(t *testing.T) {
tests := []struct {
name string
maxDurationMs int
want time.Duration
}{
{"1000ms", 1000, 1 * time.Second},
{"500ms", 500, 500 * time.Millisecond},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := &execRequestData{MaxDurationMilliseconds: tt.maxDurationMs}
got := req.maxDuration()
if got != tt.want {
t.Errorf("maxDuration() = %v, want %v", got, tt.want)
}
})
}
}
func TestExecResponseData_Success(t *testing.T) {
tests := []struct {
name string
status string
want bool
}{
{"success", resultSuccess, true},
{"compile_error", resultCompileError, false},
{"runtime_error", resultRuntimeError, false},
{"timeout", resultTimeout, false},
{"internal_error", resultInternalError, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res := &execResponseData{Status: tt.status}
got := res.success()
if got != tt.want {
t.Errorf("success() = %v, want %v", got, tt.want)
}
})
}
}
|