-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathhook_internal_test.go
More file actions
72 lines (64 loc) · 1.73 KB
/
hook_internal_test.go
File metadata and controls
72 lines (64 loc) · 1.73 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
package workflow
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/require"
)
func Test_runHooks(t *testing.T) {
ctx := t.Context()
t.Run("Return non-nil error from lookup", func(t *testing.T) {
testErr := errors.New("test error")
err := runHook[string, testStatus](
"workflow_name",
"process_name",
func(ctx context.Context, runID string) (*Record, error) {
return nil, testErr
},
func(ctx context.Context, record *TypedRecord[string, testStatus]) error {
return nil
},
)(ctx, &Event{})
require.Equal(t, testErr, err)
})
t.Run("Skip event on failure to unmarshal object", func(t *testing.T) {
err := runHook[string, testStatus](
"workflow_name",
"process_name",
func(ctx context.Context, runID string) (*Record, error) {
return &Record{
Object: []byte("INVALID JSON"),
}, nil
},
func(ctx context.Context, record *TypedRecord[string, testStatus]) error {
return nil
},
)(ctx, &Event{})
require.NoError(t, err)
})
t.Run("Return non-error if hook errors", func(t *testing.T) {
testErr := errors.New("test error")
err := runHook[string, testStatus](
"workflow_name",
"process_name",
func(ctx context.Context, runID string) (*Record, error) {
value := "data"
b, err := Marshal(&value)
require.NoError(t, err)
current := &Record{
WorkflowName: "example",
ForeignID: "32948623984623",
RunID: "JHFJDS-LSFKHJSLD-KSJDBLSL",
RunState: RunStateRunning,
Status: int(statusStart),
Object: b,
}
return current, nil
},
func(ctx context.Context, record *TypedRecord[string, testStatus]) error {
return testErr
},
)(ctx, &Event{})
require.Equal(t, testErr, err)
})
}