Skip to content

Commit c88335c

Browse files
wzshimingjsouthworth
authored andcommitted
Add test
1 parent 6f46e0d commit c88335c

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

conn_test.go

+34-2
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,43 @@ import (
1313
)
1414

1515
func TestSessionBus(t *testing.T) {
16-
_, err := SessionBus()
16+
oldConn, err := SessionBus()
1717
if err != nil {
1818
t.Error(err)
1919
}
20+
if err = oldConn.Close(); err != nil {
21+
t.Fatal(err)
22+
}
23+
if oldConn.Connected() {
24+
t.Fatal("Should be closed")
25+
}
26+
newConn, err := SessionBus()
27+
if err != nil {
28+
t.Error(err)
29+
}
30+
if newConn == oldConn {
31+
t.Fatal("Should get a new connection")
32+
}
2033
}
2134

2235
func TestSystemBus(t *testing.T) {
23-
_, err := SystemBus()
36+
oldConn, err := SystemBus()
37+
if err != nil {
38+
t.Error(err)
39+
}
40+
if err = oldConn.Close(); err != nil {
41+
t.Fatal(err)
42+
}
43+
if oldConn.Connected() {
44+
t.Fatal("Should be closed")
45+
}
46+
newConn, err := SystemBus()
2447
if err != nil {
2548
t.Error(err)
2649
}
50+
if newConn == oldConn {
51+
t.Fatal("Should get a new connection")
52+
}
2753
}
2854

2955
func TestConnectSessionBus(t *testing.T) {
@@ -34,6 +60,9 @@ func TestConnectSessionBus(t *testing.T) {
3460
if err = conn.Close(); err != nil {
3561
t.Fatal(err)
3662
}
63+
if conn.Connected() {
64+
t.Fatal("Should be closed")
65+
}
3766
}
3867

3968
func TestConnectSystemBus(t *testing.T) {
@@ -44,6 +73,9 @@ func TestConnectSystemBus(t *testing.T) {
4473
if err = conn.Close(); err != nil {
4574
t.Fatal(err)
4675
}
76+
if conn.Connected() {
77+
t.Fatal("Should be closed")
78+
}
4779
}
4880

4981
func TestSend(t *testing.T) {

0 commit comments

Comments
 (0)