From ad11e893b8c3eda4b2f7e473baf65c59d1701f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20G=C3=B3mez?= Date: Wed, 24 May 2023 01:13:58 -0300 Subject: [PATCH] Fix implementation. --- backends/grpc.go | 15 +++++++++++---- backends/grpc_test.go | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/backends/grpc.go b/backends/grpc.go index 481ef78..d851eea 100644 --- a/backends/grpc.go +++ b/backends/grpc.go @@ -28,6 +28,7 @@ type GRPC struct { dialOptions []grpc.DialOption hostname string timeout int + name string } const defaultGRPCTimeoutMs = 500 @@ -140,11 +141,17 @@ func (o *GRPC) CheckAcl(username, topic, clientid string, acc int32) (bool, erro // GetName gets the gRPC backend's name. func (o *GRPC) GetName() string { - resp, err := o.client.GetName(context.Background(), &empty.Empty{}) - if err != nil { - return "grpc get name error" + if len(o.name) == 0 { + resp, err := o.client.GetName(context.Background(), &empty.Empty{}) + + if err != nil { + o.name = "gRPC" + } else { + o.name = resp.Name + } } - return resp.Name + + return o.name } // Halt signals the gRPC backend that mosquitto is halting. diff --git a/backends/grpc_test.go b/backends/grpc_test.go index 0772e23..640a7d6 100644 --- a/backends/grpc_test.go +++ b/backends/grpc_test.go @@ -113,6 +113,9 @@ func TestGRPC(t *testing.T) { auth, err := g.GetUser(grpcUsername, grpcPassword, grpcClientId) So(err, ShouldNotBeNil) c.So(auth, ShouldBeFalse) + + name := g.GetName() + So(name, ShouldEqual, "gRPC") }) Convey("it should work after the service comes back up", func(c C) { @@ -125,6 +128,9 @@ func TestGRPC(t *testing.T) { auth, err := g.GetUser(grpcUsername, grpcPassword, grpcClientId) So(err, ShouldBeNil) c.So(auth, ShouldBeTrue) + + name := g.GetName() + So(name, ShouldEqual, "MyGRPCBackend") }) }) })