Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADDED] Stringer for connection status #812

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions nats.go
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions test/conn_test.go
Expand Up @@ -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 || fmt.Sprintf("%s", nc.Status()) != "CONNECTED"{
josephwoodward marked this conversation as resolved.
Show resolved Hide resolved
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 || fmt.Sprintf("%s", nc.Status()) != "CLOSED" {
t.Fatal("Should have status set to CLOSED")
}
if !nc.IsClosed() {
Expand Down