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

Set queue type in queue argument if it's set in QueueSettings #189

Merged
merged 3 commits into from
May 24, 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
2 changes: 1 addition & 1 deletion bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (c *Client) newBindingPath(vhost string, info BindingInfo) string {
// DELETE /api/bindings/{vhost}/e/{source}/{destination_type}/{destination}/{props}
//

// DeleteBinding delets an individual binding
// DeleteBinding deletes an individual binding
func (c *Client) DeleteBinding(vhost string, info BindingInfo) (res *http.Response, err error) {
req, err := newRequestWithBody(c, "DELETE", "bindings/"+url.PathEscape(vhost)+
"/e/"+url.PathEscape(info.Source)+"/"+url.PathEscape(string(info.DestinationType[0]))+
Expand Down
7 changes: 6 additions & 1 deletion queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type QueueInfo struct {
Vhost string `json:"vhost"`
// Is this queue durable?
Durable bool `json:"durable"`
// Is this queue auto-delted?
// Is this queue auto-deleted?
AutoDelete bool `json:"auto_delete"`
// Extra queue arguments
Arguments map[string]interface{} `json:"arguments"`
Expand Down Expand Up @@ -300,6 +300,11 @@ func (c *Client) DeclareQueue(vhost, queue string, info QueueSettings) (res *htt
if info.Arguments == nil {
info.Arguments = make(map[string]interface{})
}

if info.Type != "" {
info.Arguments["x-queue-type"] = info.Type
}

body, err := json.Marshal(info)
if err != nil {
return nil, err
Expand Down
9 changes: 5 additions & 4 deletions rabbithole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1634,18 +1634,19 @@ var _ = Describe("RabbitMQ HTTP API client", func() {
Context("PUT /queues/{vhost}/{queue}", func() {
It("declares a queue", func() {
vh := "rabbit/hole"
qn := "temporary"
qn := "temporary-declare"

_, err := rmqc.DeclareQueue(vh, qn, QueueSettings{Durable: false})
_, err := rmqc.DeclareQueue(vh, qn, QueueSettings{Durable: true, Type: "quorum"})
Ω(err).Should(BeNil())

awaitEventPropagation()
x, err := rmqc.GetQueue(vh, qn)
Ω(err).Should(BeNil())
Ω(x.Name).Should(Equal(qn))
Ω(x.Durable).Should(Equal(false))
Ω(x.Durable).Should(Equal(true))
Ω(x.AutoDelete).Should(Equal(false))
Ω(x.Vhost).Should(Equal(vh))
Ω(x.Arguments).To(HaveKeyWithValue("x-queue-type", "quorum"))

_, err = rmqc.DeleteQueue(vh, qn)
Ω(err).Should(BeNil())
Expand Down Expand Up @@ -2376,7 +2377,7 @@ var _ = Describe("RabbitMQ HTTP API client", func() {
Ω(len(list)).Should(Equal(1))
Ω(err).Should(BeNil())

var link map[string]interface{} = list[0]
var link = list[0]
Ω(link["vhost"]).Should(Equal(vhost))
Ω(link["upstream"]).Should(Equal(upstreamName))
Ω(link["type"]).Should(Equal("exchange"))
Expand Down
4 changes: 2 additions & 2 deletions shovels.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (s *ShovelURISet) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &uri); err != nil {
return err
}
*s = ShovelURISet([]string{uri})
*s = []string{uri}
return nil
}

Expand All @@ -89,7 +89,7 @@ func (s *ShovelURISet) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &uris); err != nil {
return err
}
*s = ShovelURISet(uris)
*s = uris
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion topic_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type TopicPermissionInfo struct {
User string `json:"user"`
Vhost string `json:"vhost"`

// Configuration topic-permisions
// Configuration topic-permissions
Exchange string `json:"exchange"`
// Write topic-permissions
Write string `json:"write"`
Expand Down
8 changes: 4 additions & 4 deletions unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

var _ = Describe("Unit tests", func() {
Context("DeleteAfter marshalling", func() {
It("unmarshals DeleteAfter when it is a number", func() {
It("unmarshalls DeleteAfter when it is a number", func() {
var d DeleteAfter
s := []byte("1")
err := d.UnmarshalJSON(s)
Expand All @@ -16,7 +16,7 @@ var _ = Describe("Unit tests", func() {
Ω(d).Should(Equal(DeleteAfter("1")))
})

It("unmarshals DeleteAfter when it is a quoted string", func() {
It("unmarshalls DeleteAfter when it is a quoted string", func() {
var d DeleteAfter
s := []byte("\"3\"")
err := d.UnmarshalJSON(s)
Expand All @@ -27,7 +27,7 @@ var _ = Describe("Unit tests", func() {
})

Context("ShovelURISet marshalling", func() {
It("unmarshals a single string", func() {
It("unmarshalls a single string", func() {
var us ShovelURISet
bs := []byte("\"amqp://127.0.0.1:5672\"")
err := us.UnmarshalJSON(bs)
Expand All @@ -36,7 +36,7 @@ var _ = Describe("Unit tests", func() {
Ω(us).Should(Equal(ShovelURISet([]string{"amqp://127.0.0.1:5672"})))
})

It("unmarshals a list of strings", func() {
It("unmarshalls a list of strings", func() {
var us ShovelURISet
bs := []byte("[\"amqp://127.0.0.1:5672\", \"amqp://localhost:5672\"]")
err := us.UnmarshalJSON(bs)
Expand Down
6 changes: 3 additions & 3 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ func (d *UserTags) UnmarshalJSON(b []byte) error {
t, _ := strconv.Unquote(string(b))
if b[0] == '"' {
quotedTags := strings.Split(t, ",")
tags := []string{}
var tags []string
for _, qt := range quotedTags {
tags = append(tags, qt)
}
*d = UserTags(tags)
*d = tags
return nil
}
// the value is an array
var ary []string
if err := json.Unmarshal(b, &ary); err != nil {
return err
}
*d = UserTags(ary)
*d = ary
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions vhosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ func (d *VhostTags) UnmarshalJSON(b []byte) error {
t, _ := strconv.Unquote(string(b))
if b[0] == '"' {
quotedTags := strings.Split(t, ",")
tags := []string{}
var tags []string
for _, qt := range quotedTags {
tags = append(tags, qt)
}
*d = VhostTags(tags)
*d = tags
return nil
}
// the value is an array
var ary []string
if err := json.Unmarshal(b, &ary); err != nil {
return err
}
*d = VhostTags(ary)
*d = ary
return nil
}

Expand Down