-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy_test.go
102 lines (89 loc) · 2.23 KB
/
proxy_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"sync"
"testing"
"time"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
type MockedSQS struct {
mock.Mock
}
func (c *MockedSQS) ReceiveMessage(i *sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error) {
args := c.Called(i)
ro, ok := args.Get(0).(sqs.ReceiveMessageOutput)
if !ok {
panic("Failed to cast to *sqs.ReceiveMessageOutput")
}
return &ro, args.Error(1)
}
func (c *MockedSQS) SendMessage(i *sqs.SendMessageInput) (*sqs.SendMessageOutput, error) {
args := c.Called(i)
so, ok := args.Get(0).(*sqs.SendMessageOutput)
if !ok {
panic("Failed to cast to *sqs.SendMessageOutput")
}
return so, args.Error(1)
}
func (c *MockedSQS) DeleteMessage(i *sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error) {
args := c.Called(i)
do, ok := args.Get(0).(*sqs.DeleteMessageOutput)
if !ok {
panic("Failed to cast to *sqs.DeleteMessageOutput")
}
return do, args.Error(1)
}
type MockedHook struct {
HookCounter int
Mutex sync.Mutex
}
func (h *MockedHook) Hook(p *ProxySettings, wg *sync.WaitGroup) {
defer wg.Done()
h.Mutex.Lock()
h.HookCounter++
h.Mutex.Unlock()
}
func (h *MockedHook) Move(i *sqs.ReceiveMessageInput, t TargetQueues) error {
return nil
}
func TestProxyStart(t *testing.T) {
conf := AppConfig{
ProxyOps: []ProxySettings{
ProxySettings{
Src: "https://queues.com/dummy-src",
Dest: TargetQueues{"https://queues.com/dummy-dest"},
Interval: time.Duration(10),
},
ProxySettings{
Src: "https://queues.com/dummy-src-2",
Dest: TargetQueues{"https://queues.com/dummy-dest-2"},
Interval: time.Duration(10),
},
},
}
h := MockedHook{}
p := Proxy{
WG: &sync.WaitGroup{},
Conf: &conf,
Hooker: &h,
}
p.Start()
assert.Equal(t, 2, h.HookCounter)
}
func TestCreateSQSSession(t *testing.T) {
assert.NotPanics(t, func() { CreateSQSSession() })
}
func TestNewProxy(t *testing.T) {
conf := AppConfig{
ProxyOps: []ProxySettings{
ProxySettings{
Src: "https://queues.com/dummy-src",
Dest: TargetQueues{"https://queues.com/dummy-dest"},
Interval: time.Duration(10),
},
},
}
proxy := NewProxy(&conf)
assert.Equal(t, &conf, proxy.Conf)
}