diff --git a/nats.go b/nats.go index 14b795d71..cd8aaed3d 100644 --- a/nats.go +++ b/nats.go @@ -196,6 +196,26 @@ const ( DRAINING_PUBS ) +func (s Status) String() string { + switch s { + case DISCONNECTED: + return "DISCONNECTED" + case CONNECTED: + return "CONNECTED" + case CLOSED: + return "CLOSED" + case RECONNECTING: + return "RECONNECTING" + case CONNECTING: + return "CONNECTING" + case DRAINING_SUBS: + return "DRAINING_SUBS" + case DRAINING_PUBS: + return "DRAINING_PUBS" + } + return "unknown status" +} + // ConnHandler is used for asynchronous events such as // disconnected and closed connections. type ConnHandler func(*Conn) diff --git a/test/conn_test.go b/test/conn_test.go index 115fd814c..0a70083c4 100644 --- a/test/conn_test.go +++ b/test/conn_test.go @@ -49,14 +49,15 @@ func TestConnectionStatus(t *testing.T) { nc := NewDefaultConnection(t) defer nc.Close() - if nc.Status() != nats.CONNECTED { + if nc.Status() != nats.CONNECTED || nc.Status().String() != "CONNECTED" { t.Fatal("Should have status set to CONNECTED") } + if !nc.IsConnected() { t.Fatal("Should have status set to CONNECTED") } nc.Close() - if nc.Status() != nats.CLOSED { + if nc.Status() != nats.CLOSED || nc.Status().String() != "CLOSED" { t.Fatal("Should have status set to CLOSED") } if !nc.IsClosed() {