mirror of
https://github.com/go-micro/go-micro.git
synced 2025-07-06 22:35:51 +02:00
Plugins and profiles (#2764)
* feat: more plugins * chore(ci): split out benchmarks Attempt to resolve too many open files in ci * chore(ci): split out benchmarks * fix(ci): Attempt to resolve too many open files in ci * fix: set DefaultX for cli flag and service option * fix: restore http broker * fix: default http broker * feat: full nats profile * chore: still ugly, not ready * fix: better initialization for profiles * fix(tests): comment out flaky listen tests * fix: disable benchmarks on gha * chore: cleanup, comments * chore: add nats config source
This commit is contained in:
111
broker/rabbitmq/connection_test.go
Normal file
111
broker/rabbitmq/connection_test.go
Normal file
@ -0,0 +1,111 @@
|
||||
package rabbitmq
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/streadway/amqp"
|
||||
"go-micro.dev/v5/logger"
|
||||
)
|
||||
|
||||
func TestNewRabbitMQConnURL(t *testing.T) {
|
||||
testcases := []struct {
|
||||
title string
|
||||
urls []string
|
||||
want string
|
||||
}{
|
||||
{"Multiple URLs", []string{"amqp://example.com/one", "amqp://example.com/two"}, "amqp://example.com/one"},
|
||||
{"Insecure URL", []string{"amqp://example.com"}, "amqp://example.com"},
|
||||
{"Secure URL", []string{"amqps://example.com"}, "amqps://example.com"},
|
||||
{"Invalid URL", []string{"http://example.com"}, DefaultRabbitURL},
|
||||
{"No URLs", []string{}, DefaultRabbitURL},
|
||||
}
|
||||
|
||||
for _, test := range testcases {
|
||||
conn := newRabbitMQConn(Exchange{Name: "exchange"}, test.urls, 0, false, false, false, logger.DefaultLogger)
|
||||
|
||||
if have, want := conn.url, test.want; have != want {
|
||||
t.Errorf("%s: invalid url, want %q, have %q", test.title, want, have)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTryToConnectTLS(t *testing.T) {
|
||||
var (
|
||||
dialCount, dialTLSCount int
|
||||
|
||||
err = errors.New("stop connect here")
|
||||
)
|
||||
|
||||
dialConfig = func(_ string, c amqp.Config) (*amqp.Connection, error) {
|
||||
if c.TLSClientConfig != nil {
|
||||
dialTLSCount++
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dialCount++
|
||||
return nil, err
|
||||
}
|
||||
|
||||
testcases := []struct {
|
||||
title string
|
||||
url string
|
||||
secure bool
|
||||
amqpConfig *amqp.Config
|
||||
wantTLS bool
|
||||
}{
|
||||
{"unsecure url, secure false, no tls config", "amqp://example.com", false, nil, false},
|
||||
{"secure url, secure false, no tls config", "amqps://example.com", false, nil, true},
|
||||
{"unsecure url, secure true, no tls config", "amqp://example.com", true, nil, true},
|
||||
{"unsecure url, secure false, tls config", "amqp://example.com", false, &amqp.Config{TLSClientConfig: &tls.Config{}}, true},
|
||||
}
|
||||
|
||||
for _, test := range testcases {
|
||||
dialCount, dialTLSCount = 0, 0
|
||||
|
||||
conn := newRabbitMQConn(Exchange{Name: "exchange"}, []string{test.url}, 0, false, false, false, logger.DefaultLogger)
|
||||
conn.tryConnect(test.secure, test.amqpConfig)
|
||||
|
||||
have := dialCount
|
||||
if test.wantTLS {
|
||||
have = dialTLSCount
|
||||
}
|
||||
|
||||
if have != 1 {
|
||||
t.Errorf("%s: used wrong dialer, Dial called %d times, DialTLS called %d times", test.title, dialCount, dialTLSCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRabbitMQPrefetchConfirmPublish(t *testing.T) {
|
||||
testcases := []struct {
|
||||
title string
|
||||
urls []string
|
||||
prefetchCount int
|
||||
prefetchGlobal bool
|
||||
confirmPublish bool
|
||||
}{
|
||||
{"Multiple URLs", []string{"amqp://example.com/one", "amqp://example.com/two"}, 1, true, true},
|
||||
{"Insecure URL", []string{"amqp://example.com"}, 1, true, true},
|
||||
{"Secure URL", []string{"amqps://example.com"}, 1, true, true},
|
||||
{"Invalid URL", []string{"http://example.com"}, 1, true, true},
|
||||
{"No URLs", []string{}, 1, true, true},
|
||||
}
|
||||
|
||||
for _, test := range testcases {
|
||||
conn := newRabbitMQConn(Exchange{Name: "exchange"}, test.urls, test.prefetchCount, test.prefetchGlobal, test.confirmPublish, false, logger.DefaultLogger)
|
||||
|
||||
if have, want := conn.prefetchCount, test.prefetchCount; have != want {
|
||||
t.Errorf("%s: invalid prefetch count, want %d, have %d", test.title, want, have)
|
||||
}
|
||||
|
||||
if have, want := conn.prefetchGlobal, test.prefetchGlobal; have != want {
|
||||
t.Errorf("%s: invalid prefetch global setting, want %t, have %t", test.title, want, have)
|
||||
}
|
||||
|
||||
if have, want := conn.confirmPublish, test.confirmPublish; have != want {
|
||||
t.Errorf("%s: invalid confirm setting, want %t, have %t", test.title, want, have)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user