Skip to content

Commit

Permalink
Merge pull request #225 from DmitriyMV/fix-testdialnil
Browse files Browse the repository at this point in the history
Check err != nil before using our connection in tests. Prevents panic…
  • Loading branch information
michaelklishin authored Nov 28, 2016
2 parents 280af99 + c6f897a commit 1b88538
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (

func TestChannelOpenOnAClosedConnectionFails(t *testing.T) {
conn, err := Dial("amqp://guest:guest@localhost:5672/")
if err != nil {
log.Fatalf("Could't connect to amqp server, err = %s", err)
}
conn.Close()

if !conn.IsClosed() {
log.Fatalf("connection %s is expected to be closed", conn)
}

_, err = conn.Channel()
if err != ErrClosed {
log.Fatalf("channel.open on a closed connection %s is expected to fail", conn)
Expand All @@ -21,14 +24,17 @@ func TestChannelOpenOnAClosedConnectionFails(t *testing.T) {

func TestQueueDeclareOnAClosedConnectionFails(t *testing.T) {
conn, err := Dial("amqp://guest:guest@localhost:5672/")
if err != nil {
log.Fatalf("Could't connect to amqp server, err = %s", err)
}
ch, _ := conn.Channel()

conn.Close()

if !conn.IsClosed() {
log.Fatalf("connection %s is expected to be closed", conn)
}

_, err = ch.QueueDeclare("an example", false, false, false, false, nil)
if err != ErrClosed {
log.Fatalf("queue.declare on a closed connection %s is expected to fail", conn)
Expand Down

0 comments on commit 1b88538

Please sign in to comment.