Skip to content

Commit

Permalink
fix: correct the test issue
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Sep 30, 2024
1 parent 677f3cc commit 540e0ca
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/infra/cmq/cmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (c *CMQ) Publish(ctx context.Context, id string, data []byte) error {
msg.Header = make(nats.Header)
otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(msg.Header))

if _, err := c.jetstream.PublishMsg(ctx, msg, jetstream.WithMsgID(id)); err != nil {
if _, err := c.jetstream.PublishMsg(context.Background(), msg, jetstream.WithMsgID(id)); err != nil {

Check failure on line 200 in internal/infra/cmq/cmq.go

View workflow job for this annotation

GitHub Actions / lint

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
return fmt.Errorf("jetstream publish message failed %w", err)
}

Expand Down
6 changes: 5 additions & 1 deletion internal/infra/http/handler/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func (h Event) Receive(c *fiber.Ctx) error {
}

{
ctx, span := h.Tracer.Start(ctx, "handler.event.publish", trace.WithSpanKind(trace.SpanKindProducer))
ctx, span := h.Tracer.Start(
ctx,
"handler.event.publish",
trace.WithSpanKind(trace.SpanKindProducer),
)
defer span.End()

if err := h.CMQ.Publish(ctx, rq.ID, data); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion internal/infra/http/handler/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -64,7 +65,11 @@ func (suite *EventSuite) TestHandler() {

resp, err := suite.engine.Test(req)
require.NoError(err)
require.Equal(http.StatusOK, resp.StatusCode)

body, err := io.ReadAll(resp.Body)
require.NoError(err)

require.Equal(http.StatusOK, resp.StatusCode, string(body))
require.NoError(resp.Body.Close())
}

Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dev cmd *flags:
fi
# run tests in the dev environment
test $saf_telemetry__meter__enabled="false": (dev "up")
test $saf_telemetry__meter__enabled="false": (dev "up --wait")
go test -v ./... -covermode=atomic -coverprofile=coverage.out

# run golangci-lint
Expand Down

0 comments on commit 540e0ca

Please sign in to comment.