Skip to content

Commit

Permalink
Add connection constructor (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo-Jacobs authored Sep 15, 2022
1 parent 134a7ed commit 051e018
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pubsub/transport/amqp/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ type Connection struct {
chReconnectionDelay time.Duration
}

func NewReconnectConnection(logger log.Logger, underlyingConn UnderlyingConnection, chReconnectionDelay time.Duration) *Connection {

return &Connection{
logger: logger,
underlyingConn: underlyingConn,
chReconnectionDelay: chReconnectionDelay,
}
}

func (c *Connection) Close() error {
return c.underlyingConn.Close()
}
Expand Down
12 changes: 12 additions & 0 deletions pubsub/transport/amqp/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,15 @@ func TestConnection_Channel(t *testing.T) {
// testLogger.AssertContainsSubstr(t, "channel recreation succeed")
//})
}

func TestReconnectConnection(t *testing.T) {
t.Run("basic constructor", func(t *testing.T) {
testLogger := log.NewNilLogger()
uc := &MockUnderlyingConnection{}
rc := NewReconnectConnection(testLogger, uc, time.Second)

assert.Equal(t, rc.underlyingConn, uc)
assert.Equal(t, rc.chReconnectionDelay, time.Second)
assert.NotEmpty(t, rc.logger)
})
}

0 comments on commit 051e018

Please sign in to comment.