2024-09-11 20:42:05 +08:00
|
|
|
package rabbitmq_amqp
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ = Describe("AMQP Bindings test ", func() {
|
|
|
|
|
var connection IConnection
|
|
|
|
|
var management IManagement
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
|
connection = NewAmqpConnection()
|
|
|
|
|
Expect(connection).NotTo(BeNil())
|
|
|
|
|
Expect(connection).To(BeAssignableToTypeOf(&AmqpConnection{}))
|
|
|
|
|
connectionSettings := NewConnectionSettings()
|
|
|
|
|
Expect(connectionSettings).NotTo(BeNil())
|
|
|
|
|
Expect(connectionSettings).To(BeAssignableToTypeOf(&ConnectionSettings{}))
|
|
|
|
|
err := connection.Open(context.TODO(), connectionSettings)
|
|
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
management = connection.Management()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
|
Expect(connection.Close(context.Background())).To(BeNil())
|
|
|
|
|
})
|
|
|
|
|
|
2024-09-18 00:59:33 +08:00
|
|
|
It("AMQP Bindings between Exchange and Queue Should succeed", func() {
|
|
|
|
|
const exchangeName = "Exchange_AMQP Bindings between Exchange and Queue should uccess"
|
|
|
|
|
const queueName = "Queue_AMQP Bindings between Exchange and Queue should succeed"
|
2024-11-15 15:37:28 +08:00
|
|
|
exchangeInfo, err := management.DeclareExchange(context.TODO(), &ExchangeSpecification{
|
|
|
|
|
Name: exchangeName,
|
|
|
|
|
})
|
2024-09-11 20:42:05 +08:00
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
Expect(exchangeInfo).NotTo(BeNil())
|
2024-11-15 15:37:28 +08:00
|
|
|
Expect(exchangeInfo.Name()).To(Equal(exchangeName))
|
2024-09-11 20:42:05 +08:00
|
|
|
|
2024-11-15 15:37:28 +08:00
|
|
|
queueInfo, err := management.DeclareQueue(context.TODO(), &QueueSpecification{
|
|
|
|
|
Name: queueName,
|
|
|
|
|
})
|
2024-09-11 20:42:05 +08:00
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
Expect(queueInfo).NotTo(BeNil())
|
2024-11-15 15:37:28 +08:00
|
|
|
Expect(queueInfo.Name()).To(Equal(queueName))
|
|
|
|
|
bindingPath, err := management.Bind(context.TODO(), &BindingSpecification{
|
|
|
|
|
SourceExchange: exchangeName,
|
|
|
|
|
DestinationQueue: queueName,
|
|
|
|
|
BindingKey: "routing-key",
|
|
|
|
|
})
|
2024-09-11 20:42:05 +08:00
|
|
|
Expect(err).To(BeNil())
|
2024-11-15 15:37:28 +08:00
|
|
|
err = management.Unbind(context.TODO(), bindingPath)
|
2024-09-11 20:42:05 +08:00
|
|
|
Expect(err).To(BeNil())
|
2024-11-15 15:37:28 +08:00
|
|
|
err = management.DeleteExchange(context.TODO(), exchangeName)
|
2024-09-11 20:42:05 +08:00
|
|
|
Expect(err).To(BeNil())
|
2024-11-15 15:37:28 +08:00
|
|
|
err = management.DeleteQueue(context.TODO(), queueName)
|
2024-09-11 20:42:05 +08:00
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
})
|
|
|
|
|
})
|