-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions_queue_test.go
More file actions
90 lines (81 loc) · 2.09 KB
/
Copy pathoptions_queue_test.go
File metadata and controls
90 lines (81 loc) · 2.09 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
package frame_test
import (
"context"
"strings"
"testing"
"github.com/pitabwire/frame"
)
// msgHandler is a simple test handler.
type msgHandler struct {
f func(context.Context, map[string]string, []byte) error
}
func (h *msgHandler) Handle(ctx context.Context, header map[string]string, message []byte) error {
return h.f(ctx, header, message)
}
func TestOptionEarlyFailure(t *testing.T) {
tests := []struct {
name string
reference string
queueURL string
errMsg string
isSub bool
}{
{
name: "WithRegisterPublisher empty reference reports error",
reference: "",
queueURL: "mem://test",
errMsg: "publisher reference cannot be empty",
isSub: false,
},
{
name: "WithRegisterPublisher invalid queueURL reports error",
reference: "test",
queueURL: "",
errMsg: "publisher queueURL is invalid",
isSub: false,
},
{
name: "WithRegisterSubscriber empty reference reports error",
reference: "",
queueURL: "mem://test",
errMsg: "subscriber reference cannot be empty",
isSub: true,
},
{
name: "WithRegisterSubscriber invalid queueURL reports error",
reference: "test",
queueURL: "",
errMsg: "subscriber queueURL is invalid",
isSub: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var opt frame.Option
if tt.isSub {
handler := &msgHandler{f: func(_ context.Context, _ map[string]string, _ []byte) error {
return nil
}}
opt = frame.WithRegisterSubscriber(tt.reference, tt.queueURL, handler)
} else {
opt = frame.WithRegisterPublisher(tt.reference, tt.queueURL)
}
ctx, svc := frame.NewService(opt)
defer svc.Stop(ctx)
errs := svc.GetStartupErrors()
if len(errs) == 0 {
t.Fatalf("expected startup error containing '%s', but got none", tt.errMsg)
}
found := false
for _, err := range errs {
if err != nil && strings.Contains(err.Error(), tt.errMsg) {
found = true
break
}
}
if !found {
t.Errorf("expected startup error containing '%s', got %v", tt.errMsg, errs)
}
})
}
}