forked from deepnoodle-ai/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
73 lines (59 loc) · 2.41 KB
/
errors_test.go
File metadata and controls
73 lines (59 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
package workflow
import (
"context"
"errors"
"testing"
"github.com/deepnoodle-ai/workflow/internal/require"
)
func TestWorkflowErrorWrapping(t *testing.T) {
// Test basic error creation
err := NewWorkflowError(ErrorTypeTimeout, "operation timed out")
require.Equal(t, "workflow: timeout: operation timed out", err.Error())
require.Nil(t, err.Unwrap())
// Test error wrapping
originalErr := errors.New("network connection failed")
wrappedErr := &WorkflowError{
Type: ErrorTypeTimeout,
Cause: originalErr.Error(),
Wrapped: originalErr,
}
require.Equal(t, "workflow: timeout: network connection failed", wrappedErr.Error())
require.Equal(t, originalErr, wrappedErr.Unwrap())
// Test errors.Is
require.True(t, errors.Is(wrappedErr, originalErr))
// Test errors.As
var wErr *WorkflowError
require.True(t, errors.As(wrappedErr, &wErr))
require.Equal(t, ErrorTypeTimeout, wErr.Type)
}
func TestErrorClassification(t *testing.T) {
// Test timeout classification
timeoutErr := context.DeadlineExceeded
classified := ClassifyError(timeoutErr)
require.Equal(t, ErrorTypeTimeout, classified.Type)
require.True(t, errors.Is(classified, timeoutErr))
// Test default classification
genericErr := errors.New("something went wrong")
classified = ClassifyError(genericErr)
require.Equal(t, ErrorTypeActivityFailed, classified.Type)
require.True(t, errors.Is(classified, genericErr))
// Test WorkflowError passthrough
originalWorkflowErr := NewWorkflowError(ErrorTypeFatal, "runtime error")
classified = ClassifyError(originalWorkflowErr)
require.Equal(t, originalWorkflowErr, classified)
}
func TestErrorMatching(t *testing.T) {
timeoutErr := NewWorkflowError(ErrorTypeTimeout, "timeout")
taskErr := NewWorkflowError(ErrorTypeActivityFailed, "task failed")
fatalErr := NewWorkflowError(ErrorTypeFatal, "fatal error")
// Test exact matching
require.True(t, MatchesErrorType(timeoutErr, ErrorTypeTimeout))
require.False(t, MatchesErrorType(timeoutErr, ErrorTypeActivityFailed))
// Test ErrorTypeAll matching
require.True(t, MatchesErrorType(timeoutErr, ErrorTypeAll))
require.True(t, MatchesErrorType(taskErr, ErrorTypeAll))
require.False(t, MatchesErrorType(fatalErr, ErrorTypeAll), "Fatal error should not match ErrorTypeAll")
// Test ErrorTypeActivityFailed matching
require.True(t, MatchesErrorType(taskErr, ErrorTypeActivityFailed))
require.False(t, MatchesErrorType(timeoutErr, ErrorTypeActivityFailed))
}