-
Notifications
You must be signed in to change notification settings - Fork 61
/
connect_test.go
102 lines (83 loc) · 2.27 KB
/
connect_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 gosmpp
import (
"github.com/linxGnu/gosmpp/pdu"
"sync/atomic"
"testing"
"github.com/stretchr/testify/require"
)
var currentAuth int32
var auths = [][2]string{
{"689528", "1a97ae"},
}
const (
smscAddr = "127.0.0.1:2775"
mess = "Thử nghiệm: chuẩn bị nế mễ"
)
func nextAuth() Auth {
pair := int(atomic.AddInt32(¤tAuth, 1)) % len(auths)
return Auth{
SMSC: smscAddr,
SystemID: auths[pair][0],
Password: auths[pair][1],
SystemType: "",
}
}
func TestBindingSMSC(t *testing.T) {
checker := func(t *testing.T, c Connector) {
conn, err := c.Connect()
require.Nil(t, err)
require.NotNil(t, conn)
_ = conn.Close()
}
t.Run("TX", func(t *testing.T) {
checker(t, TXConnector(NonTLSDialer, nextAuth()))
})
t.Run("RX", func(t *testing.T) {
checker(t, RXConnector(NonTLSDialer, nextAuth()))
})
t.Run("RX", func(t *testing.T) {
addrRange := pdu.AddressRange{}
addrRange.AddressRange = "31218"
checker(t, RXConnector(NonTLSDialer, nextAuth(), WithAddressRange(addrRange)))
})
t.Run("TRX", func(t *testing.T) {
checker(t, TRXConnector(NonTLSDialer, nextAuth()))
})
t.Run("TRX", func(t *testing.T) {
addrRange := pdu.AddressRange{}
addrRange.AddressRange = "31218"
checker(t, TRXConnector(NonTLSDialer, nextAuth(), WithAddressRange(addrRange)))
})
}
func TestBindingSMSC_Error(t *testing.T) {
auth := Auth{SMSC: smscAddr, SystemID: "invalid"}
checker := func(t *testing.T, c Connector) {
conn, err := c.Connect()
require.ErrorContains(t, err, "Invalid System ID")
_ = conn.Close()
}
t.Run("TX", func(t *testing.T) {
checker(t, TXConnector(NonTLSDialer, auth))
})
t.Run("RX", func(t *testing.T) {
checker(t, RXConnector(NonTLSDialer, auth))
})
t.Run("TRX", func(t *testing.T) {
checker(t, TRXConnector(NonTLSDialer, auth))
})
}
func TestBindingType(t *testing.T) {
auth := Auth{SMSC: smscAddr, SystemID: "invalid"}
t.Run("TX", func(t *testing.T) {
c := TXConnector(NonTLSDialer, auth)
require.Equal(t, c.GetBindType(), pdu.Transmitter)
})
t.Run("RX", func(t *testing.T) {
c := RXConnector(NonTLSDialer, auth)
require.Equal(t, c.GetBindType(), pdu.Receiver)
})
t.Run("TRX", func(t *testing.T) {
c := TRXConnector(NonTLSDialer, auth)
require.Equal(t, c.GetBindType(), pdu.Transceiver)
})
}