From c88335c0b1d28a30e7fc76d526a06154b85e5d97 Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Tue, 23 Mar 2021 10:55:12 +0800 Subject: [PATCH] Add test --- conn_test.go | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/conn_test.go b/conn_test.go index 8ac32b84..b73fddd8 100644 --- a/conn_test.go +++ b/conn_test.go @@ -13,17 +13,43 @@ import ( ) func TestSessionBus(t *testing.T) { - _, err := SessionBus() + oldConn, err := SessionBus() if err != nil { t.Error(err) } + if err = oldConn.Close(); err != nil { + t.Fatal(err) + } + if oldConn.Connected() { + t.Fatal("Should be closed") + } + newConn, err := SessionBus() + if err != nil { + t.Error(err) + } + if newConn == oldConn { + t.Fatal("Should get a new connection") + } } func TestSystemBus(t *testing.T) { - _, err := SystemBus() + oldConn, err := SystemBus() + if err != nil { + t.Error(err) + } + if err = oldConn.Close(); err != nil { + t.Fatal(err) + } + if oldConn.Connected() { + t.Fatal("Should be closed") + } + newConn, err := SystemBus() if err != nil { t.Error(err) } + if newConn == oldConn { + t.Fatal("Should get a new connection") + } } func TestConnectSessionBus(t *testing.T) { @@ -34,6 +60,9 @@ func TestConnectSessionBus(t *testing.T) { if err = conn.Close(); err != nil { t.Fatal(err) } + if conn.Connected() { + t.Fatal("Should be closed") + } } func TestConnectSystemBus(t *testing.T) { @@ -44,6 +73,9 @@ func TestConnectSystemBus(t *testing.T) { if err = conn.Close(); err != nil { t.Fatal(err) } + if conn.Connected() { + t.Fatal("Should be closed") + } } func TestSend(t *testing.T) {