-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
56 lines (44 loc) · 1.62 KB
/
errors_test.go
File metadata and controls
56 lines (44 loc) · 1.62 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
package forge
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestServiceError_Error(t *testing.T) {
innerErr := errors.New("inner error")
serviceErr := NewServiceError("test-service", "start", innerErr)
expected := "service test-service: start: inner error"
assert.Equal(t, expected, serviceErr.Error())
}
func TestServiceError_Unwrap(t *testing.T) {
innerErr := errors.New("inner error")
serviceErr := NewServiceError("test-service", "resolve", innerErr)
unwrapped := serviceErr.Unwrap()
assert.Equal(t, innerErr, unwrapped)
}
func TestServiceError_ErrorsAs(t *testing.T) {
innerErr := errors.New("inner error")
serviceErr := NewServiceError("test-service", "stop", innerErr)
var svcErr *ServiceError
assert.ErrorAs(t, serviceErr, &svcErr)
assert.Equal(t, "test-service", svcErr.Service)
assert.Equal(t, "stop", svcErr.Operation)
assert.Equal(t, innerErr, svcErr.Err)
}
func TestServiceError_ErrorsIs(t *testing.T) {
innerErr := errors.New("inner error")
serviceErr := NewServiceError("test-service", "health", innerErr)
assert.ErrorIs(t, serviceErr, innerErr)
}
func TestStandardErrors(t *testing.T) {
// Test error constructors exist
assert.NotNil(t, ErrServiceNotFound)
assert.NotNil(t, ErrCircularDependency)
assert.Error(t, ErrContainerStarted)
assert.Error(t, ErrScopeEnded)
// Test error constructor outputs
assert.Contains(t, ErrServiceNotFound("test").Error(), "not found")
assert.Contains(t, ErrCircularDependency([]string{"a", "b"}).Error(), "circular")
assert.Contains(t, ErrContainerStarted.Error(), "already started")
assert.Contains(t, ErrScopeEnded.Error(), "already ended")
}