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

Handle "undefined" as an auto_delete value #207

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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