forked from gjbae1212/fluent-bit-pubsub
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pubsub_test.go
84 lines (69 loc) · 2.08 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"context"
"log"
"os"
"testing"
"time"
"cloud.google.com/go/pubsub"
"github.com/stretchr/testify/assert"
)
func TestNewKeeper(t *testing.T) {
assert := assert.New(t)
_, err := NewKeeper("", "", "", nil)
assert.Error(err)
projectId := os.Getenv("PROJECT_ID")
topicName := os.Getenv("TOPIC_NAME")
jwtPath := os.Getenv("JWT_PATH")
if projectId == "" || topicName == "" || jwtPath == "" {
return
}
_, err = NewKeeper(projectId, topicName, jwtPath, nil)
assert.NoError(err)
keeper, err := NewKeeper(projectId, topicName, jwtPath, &pubsub.PublishSettings{
ByteThreshold: 10,
CountThreshold: 10,
DelayThreshold: 1 * time.Second,
Timeout: 5 * time.Second,
})
assert.NoError(err)
assert.Equal(keeper.(*GooglePubSub).topic.PublishSettings.Timeout, 5*time.Second)
assert.Equal(keeper.(*GooglePubSub).topic.PublishSettings.DelayThreshold, 1*time.Second)
assert.Equal(keeper.(*GooglePubSub).topic.PublishSettings.CountThreshold, 10)
assert.Equal(keeper.(*GooglePubSub).topic.PublishSettings.ByteThreshold, 10)
}
func TestGooglePubSub_Send(t *testing.T) {
assert := assert.New(t)
projectId := os.Getenv("PROJECT_ID")
topicName := os.Getenv("TOPIC_NAME")
jwtPath := os.Getenv("JWT_PATH")
if projectId == "" || topicName == "" || jwtPath == "" {
return
}
ctx := context.Background()
keeper, err := NewKeeper(projectId, topicName, jwtPath, nil)
assert.NoError(err)
result := keeper.Send(ctx, []byte("aaa"))
_, err = result.Get(ctx)
assert.NoError(err)
sub := keeper.(*GooglePubSub).client.Subscription(topicName)
go func() {
sub.Receive(context.Background(), func(ctx context.Context, m *pubsub.Message) {
log.Printf("Got message: %s", m.Data)
m.Ack()
})
}()
time.Sleep(5 * time.Second)
}
func TestGooglePubSub_Stop(t *testing.T) {
assert := assert.New(t)
projectId := os.Getenv("PROJECT_ID")
topicName := os.Getenv("TOPIC_NAME")
jwtPath := os.Getenv("JWT_PATH")
if projectId == "" || topicName == "" || jwtPath == "" {
return
}
keeper, err := NewKeeper(projectId, topicName, jwtPath, nil)
assert.NoError(err)
keeper.Stop()
}