Skip to content

Commit

Permalink
fix(all): linting errors, go.mod go version.
Browse files Browse the repository at this point in the history
  • Loading branch information
jochumdev committed Oct 27, 2024
1 parent a63f3f6 commit 1bca6b6
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions client/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion codecs/goccyjson/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion codecs/goccyjson/json.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package json
// Package goccyjson contains a fast replacement for encoding/json.
package goccyjson

import (
"io"
Expand Down
2 changes: 1 addition & 1 deletion codecs/json/go.mod
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions codecs/json/json.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package json contains the encoding/json en/de-coder.
package json

import (
Expand Down
2 changes: 1 addition & 1 deletion config/source/cli/tests/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 9 additions & 4 deletions event/natsjs/natsjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -173,6 +175,7 @@ func (n *NatsJS) HandleRequest(
if inErr != nil {
reply.Error = inErr.Error()
}

reply.Metadata = md

b, err := n.codec.Encode(reply)
Expand All @@ -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)
Expand All @@ -213,6 +217,7 @@ func (n *NatsJS) HandleRequest(
}

wPool.Start()

for {
msg, err := sub.NextMsgWithContext(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion event/tests/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 9 additions & 2 deletions event/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/suite"
)

// Suite is our testsuite.
type Suite struct {
suite.Suite

Expand All @@ -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)
Expand All @@ -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}
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion util/tests/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 1bca6b6

Please sign in to comment.