Repository navigation
Expand file tree
/
Copy patherrors_test.go
More file actions
193 lines (180 loc) · 4.58 KB
/
Copy patherrors_test.go
File metadata and controls
193 lines (180 loc) · 4.58 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Copyright (c) 2025, The GoKit Authors
// MIT License
// All rights reserved.
package bunmq
import (
"errors"
"testing"
)
func TestBunMQError_Error(t *testing.T) {
tests := []struct {
name string
message string
expected string
}{
{
name: "simple error message",
message: "connection failed",
expected: "connection failed",
},
{
name: "empty error message",
message: "",
expected: "",
},
{
name: "complex error message",
message: "failed to establish connection to rabbitmq://localhost:5672",
expected: "failed to establish connection to rabbitmq://localhost:5672",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := &BunMQError{Message: tt.message}
if got := err.Error(); got != tt.expected {
t.Errorf("BunMQError.Error() = %v, want %v", got, tt.expected)
}
})
}
}
func TestNewBunMQError(t *testing.T) {
tests := []struct {
name string
message string
expected string
}{
{
name: "create error with message",
message: "test error",
expected: "test error",
},
{
name: "create error with empty message",
message: "",
expected: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := NewBunMQError(tt.message)
if err == nil {
t.Fatal("NewBunMQError() returned nil")
return
}
if err.Message != tt.expected {
t.Errorf("NewBunMQError().Message = %v, want %v", err.Message, tt.expected)
}
if err.Error() != tt.expected {
t.Errorf("NewBunMQError().Error() = %v, want %v", err.Error(), tt.expected)
}
})
}
}
func TestErrorFunctions(t *testing.T) {
tests := []struct {
name string
fn func(error) error
input error
expected string
}{
{
name: "rabbitMQDialError wraps error",
fn: rabbitMQDialError,
input: errors.New("dial tcp: connection refused"),
expected: "dial tcp: connection refused",
},
{
name: "getChannelError wraps error",
fn: getChannelError,
input: errors.New("channel creation failed"),
expected: "channel creation failed",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.fn(tt.input)
if err == nil {
t.Fatal("error function returned nil")
}
if err.Error() != tt.expected {
t.Errorf("error function result = %v, want %v", err.Error(), tt.expected)
}
// Verify it's a BunMQError
bunErr, ok := err.(*BunMQError)
if !ok {
t.Errorf("error function should return *BunMQError, got %T", err)
}
if bunErr.Message != tt.expected {
t.Errorf("BunMQError.Message = %v, want %v", bunErr.Message, tt.expected)
}
})
}
}
func TestPredefinedErrors(t *testing.T) {
tests := []struct {
name string
err error
expected string
}{
{
name: "NullableChannelError",
err: NullableChannelError,
expected: "channel cant be null",
},
{
name: "ConsumerAlreadyRegisteredForTheMessageError",
err: ConsumerAlreadyRegisteredForTheMessageError,
expected: "consumer already registered for the message",
},
{
name: "NotFoundQueueDefinitionError",
err: NotFoundQueueDefinitionError,
expected: "not found queue definition",
},
{
name: "InvalidDispatchParamsError",
err: InvalidDispatchParamsError,
expected: "register dispatch with invalid parameters",
},
{
name: "QueueDefinitionNotFoundError",
err: QueueDefinitionNotFoundError,
expected: "any queue definition was founded to the given queue",
},
{
name: "ReceivedMessageWithUnformattedHeaderError",
err: ReceivedMessageWithUnformattedHeaderError,
expected: "received message with unformatted headers",
},
{
name: "RetryableError",
err: RetryableError,
expected: "error to process this message, retry latter",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.err == nil {
t.Fatal("predefined error is nil")
}
if tt.err.Error() != tt.expected {
t.Errorf("error message = %v, want %v", tt.err.Error(), tt.expected)
}
// Verify it's a BunMQError
bunErr, ok := tt.err.(*BunMQError)
if !ok {
t.Errorf("predefined error should be *BunMQError, got %T", tt.err)
}
if bunErr.Message != tt.expected {
t.Errorf("BunMQError.Message = %v, want %v", bunErr.Message, tt.expected)
}
})
}
}
func TestBunMQError_Interface(t *testing.T) {
// Verify BunMQError implements error interface
var err error = &BunMQError{Message: "test"}
if err.Error() != "test" {
t.Errorf("BunMQError does not properly implement error interface")
}
}