Skip to content

Commit

Permalink
fix: AddOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
janiltonmaciel committed Aug 20, 2020
1 parent 20ed533 commit f04cf70
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ func main() {
[![GoDoc]( https://godoc.org/github.com/globocom/enqueuestomp?status.svg)](https://pkg.go.dev/github.com/globocom/enqueuestomp)

Full documentation for the package can be viewed online using the GoDoc site here:
https://pkg.go.dev/github.com/globocom/enqueuestomp
[https://pkg.go.dev/github.com/globocom/enqueuestomp](https://pkg.go.dev/github.com/globocom/enqueuestomp)
6 changes: 5 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ type Config struct {
}

func (c *Config) AddOptions(opts ...func(*stomp.Conn) error) {
c.Options = opts
if len(c.Options) == 0 {
c.Options = opts
} else {
c.Options = append(c.Options, opts...)
}
}

func (c *Config) init() {
Expand Down
42 changes: 42 additions & 0 deletions enqueuestomp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (s *EnqueueStompSuite) TestConfigMaxRetriesConnect(c *check.C) {
config := enqueue.Config()
c.Assert(config.RetriesConnect, check.Equals, 5)
}

func (s *EnqueueStompSuite) TestConfigWithOptions(c *check.C) {
enqueueConfig := enqueuestomp.Config{}
enqueueConfig.AddOptions(
Expand Down Expand Up @@ -389,3 +390,44 @@ func (s *EnqueueStompSuite) TestDisconnect(c *check.C) {
err = enqueue.Disconnect()
c.Assert(err, check.IsNil)
}

func (s *EnqueueStompSuite) TestSendConfigOptions(c *check.C) {
enqueue, err := enqueuestomp.NewEnqueueStomp(
enqueuestomp.Config{},
)
c.Assert(err, check.IsNil)

sc := enqueuestomp.SendConfig{}
sc.AddOptions(stomp.SendOpt.Header("persistent", "true"))
sc.AddOptions(stomp.SendOpt.Header("X-header", "myheader"))
c.Assert(sc.Options, check.HasLen, 2)

err = enqueue.SendQueue(queueName, queueBody, sc)
c.Assert(err, check.IsNil)
s.waitQueueSize(enqueue)

enqueueCount := s.j.StatQueue(queueName, "EnqueueCount")
c.Assert(enqueueCount, check.Equals, "1")
}

func (s *EnqueueStompSuite) TestConfigOptions(c *check.C) {
enqueueConfig := enqueuestomp.Config{}
enqueueConfig.AddOptions(
stomp.ConnOpt.HeartBeat(0*time.Second, 0*time.Second),
)
enqueueConfig.AddOptions(
stomp.ConnOpt.Login("guest", "guest"),
)
c.Assert(enqueueConfig.Options, check.HasLen, 2)

enqueue, err := enqueuestomp.NewEnqueueStomp(enqueueConfig)
c.Assert(err, check.IsNil)

sc := enqueuestomp.SendConfig{}
err = enqueue.SendQueue(queueName, queueBody, sc)
c.Assert(err, check.IsNil)
s.waitQueueSize(enqueue)

enqueueCount := s.j.StatQueue(queueName, "EnqueueCount")
c.Assert(enqueueCount, check.Equals, "1")
}
6 changes: 5 additions & 1 deletion sendconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ type SendConfig struct {
}

func (sc *SendConfig) AddOptions(opts ...func(*frame.Frame) error) {
sc.Options = opts
if len(sc.Options) == 0 {
sc.Options = opts
} else {
sc.Options = append(sc.Options, opts...)
}
}

func (sc *SendConfig) init() {
Expand Down

0 comments on commit f04cf70

Please sign in to comment.