diff --git a/client/tests/tests.go b/client/tests/tests.go index d3270f3e..025fd21a 100644 --- a/client/tests/tests.go +++ b/client/tests/tests.go @@ -19,6 +19,7 @@ import ( "github.com/stretchr/testify/suite" "golang.org/x/exp/slices" + // Blank imports here are fine. _ "github.com/go-orb/plugins-experimental/registry/mdns" _ "github.com/go-orb/plugins/codecs/json" _ "github.com/go-orb/plugins/codecs/jsonpb" diff --git a/codecs/goccyjson/go.mod b/codecs/goccyjson/go.mod index 69d6613b..9d175e07 100644 --- a/codecs/goccyjson/go.mod +++ b/codecs/goccyjson/go.mod @@ -1,6 +1,6 @@ module github.com/go-orb/plugins/codecs/goccyjson -go 1.23.2 +go 1.23 require ( github.com/go-orb/go-orb v0.0.0-20241009192637-67e6b576f4f3 diff --git a/codecs/goccyjson/json.go b/codecs/goccyjson/json.go index 500150b3..53c17230 100644 --- a/codecs/goccyjson/json.go +++ b/codecs/goccyjson/json.go @@ -1,4 +1,5 @@ -package json +// Package goccyjson contains a fast replacement for encoding/json. +package goccyjson import ( "io" diff --git a/codecs/json/go.mod b/codecs/json/go.mod index 4dc6341d..bca49be4 100644 --- a/codecs/json/go.mod +++ b/codecs/json/go.mod @@ -1,6 +1,6 @@ module github.com/go-orb/plugins/codecs/json -go 1.23.2 +go 1.23 require github.com/go-orb/go-orb v0.0.0-20241009192637-67e6b576f4f3 diff --git a/codecs/json/json.go b/codecs/json/json.go index 32d5e3cd..15682187 100644 --- a/codecs/json/json.go +++ b/codecs/json/json.go @@ -1,3 +1,4 @@ +// Package json contains the encoding/json en/de-coder. package json import ( diff --git a/config/source/cli/tests/go.mod b/config/source/cli/tests/go.mod index 8d4a4e3e..41e7f369 100644 --- a/config/source/cli/tests/go.mod +++ b/config/source/cli/tests/go.mod @@ -1,6 +1,6 @@ module github.com/go-orb/plugins/config/source/cli/tests -go 1.23.2 +go 1.23 require ( github.com/go-orb/go-orb v0.0.1 diff --git a/event/natsjs/natsjs.go b/event/natsjs/natsjs.go index 9fa914ac..7c0c4ca2 100644 --- a/event/natsjs/natsjs.go +++ b/event/natsjs/natsjs.go @@ -134,14 +134,16 @@ func (n *NatsJS) Request( return nil, err } - if len(reply.Error) != 0 { - return nil, errors.New(reply.Error) + if len(reply.GetError()) != 0 { + return nil, errors.New(reply.GetError()) } return reply.GetData(), nil } // HandleRequest subscribes to the given topic and handles the requests. +// +//nolint:funlen func (n *NatsJS) HandleRequest( ctx context.Context, topic string, @@ -173,6 +175,7 @@ func (n *NatsJS) HandleRequest( if inErr != nil { reply.Error = inErr.Error() } + reply.Metadata = md b, err := n.codec.Encode(reply) @@ -194,13 +197,14 @@ func (n *NatsJS) HandleRequest( if err != nil { n.logger.Error("while decoding the request", "error", err) replyFunc(ctx, nil, fmt.Errorf("while decoding the request: %w", err)) + return } evReq := n.evReqPool.Get() defer n.evReqPool.Put(evReq) - evReq.ContentType = req.ContentType - evReq.Data = req.Data + evReq.ContentType = req.GetContentType() + evReq.Data = req.GetData() evReq.SetReplyFunc(replyFunc) callbackHandler(context.Background(), evReq) @@ -213,6 +217,7 @@ func (n *NatsJS) HandleRequest( } wPool.Start() + for { msg, err := sub.NextMsgWithContext(ctx) if err != nil { diff --git a/event/tests/go.mod b/event/tests/go.mod index 6d44320e..54c2200f 100644 --- a/event/tests/go.mod +++ b/event/tests/go.mod @@ -1,6 +1,6 @@ module github.com/go-orb/plugins/event/tests -go 1.23.1 +go 1.23 require ( github.com/go-orb/go-orb v0.0.0-20241009192637-67e6b576f4f3 diff --git a/event/tests/tests.go b/event/tests/tests.go index e484fa45..c6d13167 100644 --- a/event/tests/tests.go +++ b/event/tests/tests.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/suite" ) +// Suite is our testsuite. type Suite struct { suite.Suite @@ -20,20 +21,22 @@ type Suite struct { handler event.Handler } +// New creates a new testsuite. func New(handler event.Handler) *Suite { return &Suite{ handler: handler, } } -func (s *Suite) echoHandler(ctx context.Context, req *echopb.Req) (*echopb.Resp, error) { - if req.Error { +func (s *Suite) echoHandler(_ context.Context, req *echopb.Req) (*echopb.Resp, error) { + if req.GetError() { return nil, errors.New("here's the error you asked for") } return &echopb.Resp{Payload: req.GetPayload()}, nil } +// SetupSuite creates the handler. func (s *Suite) SetupSuite() { ctx, cancel := context.WithCancel(context.Background()) event.HandleRequest(ctx, s.handler, "echo", s.echoHandler) @@ -43,16 +46,19 @@ func (s *Suite) SetupSuite() { time.Sleep(time.Second) } +// TearDownSuite stops the handler. func (s *Suite) TearDownSuite() { s.cancelRequestHandler() } +// TestBadRequest tests a bad request. func (s *Suite) TestBadRequest() { req := &echopb.Req{Error: true} _, err := event.Request[echopb.Resp](context.Background(), s.handler, "echo", req) s.Require().Error(err) } +// TestRequest tests a request. func (s *Suite) TestRequest() { payload := []byte("asdf1234") req := &echopb.Req{Payload: payload} @@ -63,6 +69,7 @@ func (s *Suite) TestRequest() { s.Require().Equal(payload, resp.GetPayload()) } +// BenchmarkRequest runs a benchmark on requests. func (s *Suite) BenchmarkRequest(b *testing.B) { b.Helper() diff --git a/util/tests/go.mod b/util/tests/go.mod index f92b0472..a680e20f 100644 --- a/util/tests/go.mod +++ b/util/tests/go.mod @@ -1,6 +1,6 @@ module github.com/go-orb/plugins/util/tests -go 1.23.2 +go 1.23 require ( github.com/stretchr/testify v1.9.0