-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
137 lines (116 loc) · 3.19 KB
/
errors_test.go
File metadata and controls
137 lines (116 loc) · 3.19 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
package farp
import (
"errors"
"testing"
)
func TestManifestError_Error(t *testing.T) {
baseErr := errors.New("test error")
manifestErr := &ManifestError{
ServiceName: "test-service",
InstanceID: "instance-123",
Err: baseErr,
}
expected := "manifest error for service=test-service instance=instance-123: test error"
if got := manifestErr.Error(); got != expected {
t.Errorf("ManifestError.Error() = %v, want %v", got, expected)
}
}
func TestManifestError_Unwrap(t *testing.T) {
baseErr := errors.New("test error")
manifestErr := &ManifestError{
ServiceName: "test-service",
InstanceID: "instance-123",
Err: baseErr,
}
unwrapped := manifestErr.Unwrap()
if !errors.Is(unwrapped, baseErr) {
t.Errorf("ManifestError.Unwrap() = %v, want %v", unwrapped, baseErr)
}
if !errors.Is(manifestErr, baseErr) {
t.Error("ManifestError should wrap baseErr")
}
}
func TestSchemaError_Error(t *testing.T) {
baseErr := errors.New("test error")
schemaErr := &SchemaError{
Type: SchemaTypeOpenAPI,
Path: "/schemas/test/v1",
Err: baseErr,
}
expected := "schema error type=openapi path=/schemas/test/v1: test error"
if got := schemaErr.Error(); got != expected {
t.Errorf("SchemaError.Error() = %v, want %v", got, expected)
}
}
func TestSchemaError_Unwrap(t *testing.T) {
baseErr := errors.New("test error")
schemaErr := &SchemaError{
Type: SchemaTypeOpenAPI,
Path: "/schemas/test/v1",
Err: baseErr,
}
unwrapped := schemaErr.Unwrap()
if !errors.Is(unwrapped, baseErr) {
t.Errorf("SchemaError.Unwrap() = %v, want %v", unwrapped, baseErr)
}
if !errors.Is(schemaErr, baseErr) {
t.Error("SchemaError should wrap baseErr")
}
}
func TestValidationError_Error(t *testing.T) {
validationErr := &ValidationError{
Field: "service_name",
Message: "service name is required",
}
expected := "validation error: field=service_name message=service name is required"
if got := validationErr.Error(); got != expected {
t.Errorf("ValidationError.Error() = %v, want %v", got, expected)
}
}
func TestErrorConstants(t *testing.T) {
// Test that all error constants are defined and not nil
errorConstants := []error{
ErrManifestNotFound,
ErrSchemaNotFound,
ErrInvalidManifest,
ErrInvalidSchema,
ErrSchemaToLarge,
ErrChecksumMismatch,
ErrUnsupportedType,
ErrBackendUnavailable,
ErrIncompatibleVersion,
ErrInvalidLocation,
ErrProviderNotFound,
ErrRegistryNotConfigured,
ErrSchemaFetchFailed,
ErrValidationFailed,
}
for i, err := range errorConstants {
if err == nil {
t.Errorf("error constant at index %d is nil", i)
}
if err.Error() == "" {
t.Errorf("error constant at index %d has empty message", i)
}
}
}
func TestErrorWrapping(t *testing.T) {
// Test that errors.Is works with custom error types
baseErr := errors.New("base error")
manifestErr := &ManifestError{
ServiceName: "test",
InstanceID: "123",
Err: baseErr,
}
if !errors.Is(manifestErr, baseErr) {
t.Error("ManifestError should be identifiable with errors.Is")
}
schemaErr := &SchemaError{
Type: SchemaTypeOpenAPI,
Path: "/test",
Err: baseErr,
}
if !errors.Is(schemaErr, baseErr) {
t.Error("SchemaError should be identifiable with errors.Is")
}
}