forked from dapr/go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpubsub_test.go
69 lines (57 loc) · 1.61 KB
/
pubsub_test.go
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
package client
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
type _testCustomContentwithText struct {
Key1, Key2 string
}
type _testCustomContentwithTextandNumbers struct {
Key1 string
Key2 int
}
type _testCustomContentwithSlices struct {
Key1 []string
Key2 []int
}
// go test -timeout 30s ./client -count 1 -run ^TestPublishEvent$
func TestPublishEvent(t *testing.T) {
ctx := context.Background()
t.Run("with data", func(t *testing.T) {
err := testClient.PublishEvent(ctx, "messages", "test", []byte("ping"))
assert.Nil(t, err)
})
t.Run("without data", func(t *testing.T) {
err := testClient.PublishEvent(ctx, "messages", "test", nil)
assert.Nil(t, err)
})
t.Run("with empty topic name", func(t *testing.T) {
err := testClient.PublishEvent(ctx, "messages", "", []byte("ping"))
assert.NotNil(t, err)
})
t.Run("from struct with text", func(t *testing.T) {
testdata := _testStructwithText{
Key1: "value1",
Key2: "value2",
}
err := testClient.PublishEventfromCustomContent(ctx, "messages", "test", testdata)
assert.Nil(t, err)
})
t.Run("from struct with text and numbers", func(t *testing.T) {
testdata := _testStructwithTextandNumbers{
Key1: "value1",
Key2: 2500,
}
err := testClient.PublishEventfromCustomContent(ctx, "messages", "test", testdata)
assert.Nil(t, err)
})
t.Run("from struct with slices", func(t *testing.T) {
testdata := _testStructwithSlices{
Key1: []string{"value1", "value2", "value3"},
Key2: []int{25, 40, 600},
}
err := testClient.PublishEventfromCustomContent(ctx, "messages", "test", testdata)
assert.Nil(t, err)
})
}