-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopic_test.go
More file actions
36 lines (29 loc) · 885 Bytes
/
topic_test.go
File metadata and controls
36 lines (29 loc) · 885 Bytes
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
package events
import "testing"
type userCreated struct{}
type customTopicEvent struct{}
func (customTopicEvent) Topic() string { return "custom.topic" }
func TestResolveTopicUsesTypeName(t *testing.T) {
topic, _, err := resolveTopic(userCreated{})
if err != nil {
t.Fatalf("resolveTopic returned error: %v", err)
}
if topic != "user.created" {
t.Fatalf("topic = %q, want %q", topic, "user.created")
}
}
func TestResolveTopicUsesOverride(t *testing.T) {
topic, _, err := resolveTopic(customTopicEvent{})
if err != nil {
t.Fatalf("resolveTopic returned error: %v", err)
}
if topic != "custom.topic" {
t.Fatalf("topic = %q, want %q", topic, "custom.topic")
}
}
func TestResolveTopicRejectsNil(t *testing.T) {
var event *userCreated
if _, _, err := resolveTopic(event); err != ErrNilEvent {
t.Fatalf("resolveTopic error = %v, want %v", err, ErrNilEvent)
}
}