package s3api import ( "testing" "github.com/seaweedfs/seaweedfs/weed/cluster" "github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/util" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) func TestNotificationBrokersStartWithTheGatewaysOwn(t *testing.T) { s3a := &S3ApiServer{option: &S3ApiServerOption{MqBroker: "10.0.0.1:17777"}} require.Equal(t, []string{"10.0.0.1:17777"}, s3a.notificationBrokers()) none := &S3ApiServer{option: &S3ApiServerOption{}} require.Empty(t, none.notificationBrokers()) } func TestABadBrokerTLSConfigTurnsNotificationsOff(t *testing.T) { v := util.GetViper() v.Set("grpc.msg_broker.cert", "/nonexistent/broker.crt") t.Cleanup(func() { v.Set("grpc.msg_broker.cert", "") }) s3a := &S3ApiServer{option: &S3ApiServerOption{}} require.Nil(t, s3a.newNotificationPublisher(), "a cert without its key must leave notifications off, not stop the gateway") v.Set("grpc.msg_broker.cert", "") publisher := s3a.newNotificationPublisher() require.NotNil(t, publisher) publisher.Close() } func TestABadBrokerTLSConfigTurnsForwardingOff(t *testing.T) { v := util.GetViper() v.Set("grpc.msg_broker.cert", "/nonexistent/broker.crt") t.Cleanup(func() { v.Set("grpc.msg_broker.cert", "") }) option := &S3ApiServerOption{Filers: []pb.ServerAddress{"127.0.0.1:8888"}, GrpcDialOption: grpc.WithTransportCredentials(insecure.NewCredentials())} s3a := &S3ApiServer{option: option, objectWriteLockClient: cluster.NewLockClient(option.GrpcDialOption, option.Filers[0])} require.Nil(t, s3a.newNotificationForwarder(), "a cert without its key must leave forwarding off, not stop the gateway") v.Set("grpc.msg_broker.cert", "") forwarder := s3a.newNotificationForwarder() require.NotNil(t, forwarder) forwarder.Close() }