Skip to content

Commit

Permalink
Merge pull request #207 from michaelklishin/undefined-autodelete
Browse files Browse the repository at this point in the history
Handle "undefined" as an auto_delete value
  • Loading branch information
michaelklishin authored Sep 16, 2021
2 parents 5507b1d + 930abe9 commit 15dc494
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
21 changes: 21 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rabbithole

import (
"encoding/json"
"errors"
"strconv"
)

Expand Down Expand Up @@ -99,3 +100,23 @@ func (s *URISet) UnmarshalJSON(b []byte) error {
*s = uris
return nil
}

// AutoDelete is a boolean but RabbitMQ may return the string "undefined"
type AutoDelete bool

// UnmarshalJSON can unmarshal a string or a boolean
func (d *AutoDelete) UnmarshalJSON(b []byte) error {
switch string(b) {
case "\"undefined\"":
// auto_delete is "undefined", map it to true
*d = AutoDelete(true)
case "true":
*d = AutoDelete(true)
case "false":
*d = AutoDelete(false)
default:
return errors.New("Unknown value of auto_delete")
}

return nil
}
2 changes: 1 addition & 1 deletion exchanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ExchangeInfo struct {
Vhost string `json:"vhost"`
Type string `json:"type"`
Durable bool `json:"durable"`
AutoDelete bool `json:"auto_delete"`
AutoDelete AutoDelete `json:"auto_delete"`
Internal bool `json:"internal"`
Arguments map[string]interface{} `json:"arguments"`

Expand Down
2 changes: 1 addition & 1 deletion queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type QueueInfo struct {
// Is this queue durable?
Durable bool `json:"durable"`
// Is this queue auto-deleted?
AutoDelete bool `json:"auto_delete"`
AutoDelete AutoDelete `json:"auto_delete"`
// Is this queue exclusive?
Exclusive bool `json:"exclusive"`
// Extra queue arguments
Expand Down
6 changes: 3 additions & 3 deletions rabbithole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ var _ = Describe("RabbitMQ HTTP API client", func() {
Ω(err).Should(BeNil())
Ω(x.Name).Should(Equal("amq.fanout"))
Ω(x.Durable).Should(Equal(true))
Ω(x.AutoDelete).Should(Equal(false))
Ω(bool(x.AutoDelete)).Should(Equal(false))
Ω(x.Internal).Should(Equal(false))
Ω(x.Type).Should(Equal("fanout"))
Ω(x.Vhost).Should(Equal("rabbit/hole"))
Expand Down Expand Up @@ -1637,7 +1637,7 @@ var _ = Describe("RabbitMQ HTTP API client", func() {
Ω(err).Should(BeNil())
Ω(x.Name).Should(Equal(xn))
Ω(x.Durable).Should(Equal(false))
Ω(x.AutoDelete).Should(Equal(false))
Ω(bool(x.AutoDelete)).Should(Equal(false))
Ω(x.Type).Should(Equal("fanout"))
Ω(x.Vhost).Should(Equal(vh))

Expand Down Expand Up @@ -1678,7 +1678,7 @@ var _ = Describe("RabbitMQ HTTP API client", func() {
Ω(err).Should(BeNil())
Ω(x.Name).Should(Equal(qn))
Ω(x.Durable).Should(Equal(true))
Ω(x.AutoDelete).Should(Equal(false))
Ω(bool(x.AutoDelete)).Should(Equal(false))
Ω(x.Vhost).Should(Equal(vh))
Ω(x.Arguments).To(HaveKeyWithValue("x-queue-type", "quorum"))

Expand Down

0 comments on commit 15dc494

Please sign in to comment.