-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_test.go
More file actions
91 lines (81 loc) · 1.73 KB
/
Copy pathhandler_test.go
File metadata and controls
91 lines (81 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package gqm
import (
"context"
"testing"
)
func TestIsFailure_NilPanics(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("expected panic for nil predicate")
}
}()
IsFailure(nil)
}
func TestIsFailure_Valid(t *testing.T) {
fn := func(err error) bool { return true }
opt := IsFailure(fn)
cfg := &handlerConfig{}
opt(cfg)
if cfg.isFailure == nil {
t.Error("isFailure should be set")
}
}
func TestOnSuccess_NilPanics(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("expected panic for nil callback")
}
}()
OnSuccess(nil)
}
func TestOnSuccess_Valid(t *testing.T) {
fn := func(ctx context.Context, job *Job) {}
opt := OnSuccess(fn)
cfg := &handlerConfig{}
opt(cfg)
if cfg.onSuccess == nil {
t.Error("onSuccess should be set")
}
}
func TestOnFailure_NilPanics(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("expected panic for nil callback")
}
}()
OnFailure(nil)
}
func TestOnFailure_Valid(t *testing.T) {
fn := func(ctx context.Context, job *Job, err error) {}
opt := OnFailure(fn)
cfg := &handlerConfig{}
opt(cfg)
if cfg.onFailure == nil {
t.Error("onFailure should be set")
}
}
func TestOnComplete_NilPanics(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("expected panic for nil callback")
}
}()
OnComplete(nil)
}
func TestOnComplete_Valid(t *testing.T) {
fn := func(ctx context.Context, job *Job, err error) {}
opt := OnComplete(fn)
cfg := &handlerConfig{}
opt(cfg)
if cfg.onComplete == nil {
t.Error("onComplete should be set")
}
}
func TestWorkers_Valid(t *testing.T) {
opt := Workers(10)
cfg := &handlerConfig{}
opt(cfg)
if cfg.workers != 10 {
t.Errorf("workers = %d, want 10", cfg.workers)
}
}