forked from matiasinsaurralde/go-e2b
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
95 lines (87 loc) · 2.41 KB
/
Copy patherrors_test.go
File metadata and controls
95 lines (87 loc) · 2.41 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
package e2b
import (
"strings"
"testing"
)
func TestErrorWithStatusCode(t *testing.T) {
e := &Error{StatusCode: 500, Message: "internal error"}
got := e.Error()
if !strings.Contains(got, "500") || !strings.Contains(got, "internal error") {
t.Errorf("Error() = %q, want status code and message", got)
}
}
func TestErrorWithoutStatusCode(t *testing.T) {
e := &Error{Message: "something failed"}
got := e.Error()
if strings.Contains(got, "status") {
t.Errorf("Error() = %q, should not contain 'status' when code is 0", got)
}
if !strings.Contains(got, "something failed") {
t.Errorf("Error() = %q, want message", got)
}
}
func TestSandboxNotFoundError(t *testing.T) {
e := &SandboxNotFoundError{SandboxID: "abc123"}
got := e.Error()
if !strings.Contains(got, "abc123") {
t.Errorf("Error() = %q, want sandbox ID", got)
}
}
func TestTimeoutError(t *testing.T) {
e := &TimeoutError{Message: "deadline exceeded"}
got := e.Error()
if !strings.Contains(got, "deadline exceeded") {
t.Errorf("Error() = %q, want message", got)
}
}
func TestTemplateBuildErrorWithStep(t *testing.T) {
e := &TemplateBuildError{
TemplateID: "tmpl-abc",
BuildID: "build-123",
Reason: BuildStatusReason{
Message: "command exited with code 1",
Step: "run",
},
}
got := e.Error()
want := "e2b: template build failed: command exited with code 1 (step: run)"
if got != want {
t.Errorf("Error() = %q, want %q", got, want)
}
}
func TestTemplateBuildErrorWithoutStep(t *testing.T) {
e := &TemplateBuildError{
TemplateID: "tmpl-abc",
BuildID: "build-123",
Reason: BuildStatusReason{
Message: "internal server error",
},
}
got := e.Error()
want := "e2b: template build failed: internal server error"
if got != want {
t.Errorf("Error() = %q, want %q", got, want)
}
}
func TestTemplateBuildErrorFields(t *testing.T) {
e := &TemplateBuildError{
TemplateID: "tmpl-xyz",
BuildID: "build-456",
Reason: BuildStatusReason{
Message: "image not found",
Step: "pull",
LogEntries: []BuildLogEntry{
{Timestamp: "2026-06-17T10:00:00Z", Message: "pulling image", Level: "error"},
},
},
}
if e.TemplateID != "tmpl-xyz" {
t.Errorf("TemplateID = %q, want %q", e.TemplateID, "tmpl-xyz")
}
if e.BuildID != "build-456" {
t.Errorf("BuildID = %q, want %q", e.BuildID, "build-456")
}
if len(e.Reason.LogEntries) != 1 {
t.Errorf("len(Reason.LogEntries) = %d, want 1", len(e.Reason.LogEntries))
}
}