Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/pr-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: PR Check

on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened

permissions:
contents: read
pull-requests: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24"

- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Download dependencies
run: go mod download

- name: Generate mocks
run: |
go install github.com/vektra/mockery/v3@v3.5.0
mockery

- name: Run tests with coverage
run: go test -timeout 3m -coverprofile=coverage.txt -covermode=atomic ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5.4.3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.txt
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
3 changes: 1 addition & 2 deletions commands/track_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"github.com/urfave/cli/v2"
"github.com/vmihailenco/msgpack/v5"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace/noop"
)
Expand Down Expand Up @@ -111,7 +110,7 @@ func (s *trackTestSuite) TestTrackWithSendData() {

var payload model.PostTrackArgs

err = msgpack.Unmarshal(body, &payload)
err = model.MsgpackDecode(body, &payload)
assert.Nil(s.T(), err)

// allow first sync so no need to check the minimum length
Expand Down
3 changes: 1 addition & 2 deletions daemon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/malamtime/cli/model"
"github.com/vmihailenco/msgpack/v5"
)

func IsSocketReady(ctx context.Context, socketPath string) bool {
Expand Down Expand Up @@ -38,7 +37,7 @@ func SendLocalDataToSocket(
},
}

encoded, err := msgpack.Marshal(data)
encoded, err := model.MsgpackEncode(data)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log/slog"

"github.com/ThreeDotsLabs/watermill/message"
"github.com/vmihailenco/msgpack/v5"
"github.com/malamtime/cli/model"
)

func SocketTopicProccessor(messages <-chan *message.Message) {
Expand All @@ -14,7 +14,7 @@ func SocketTopicProccessor(messages <-chan *message.Message) {
slog.InfoContext(ctx, "received message: ", slog.String("msg.uuid", msg.UUID))

var socketMsg SocketMessage
if err := msgpack.Unmarshal(msg.Payload, &socketMsg); err != nil {
if err := model.MsgpackDecode(msg.Payload, &socketMsg); err != nil {
slog.ErrorContext(ctx, "failed to parse socket message", slog.Any("err", err))
msg.Nack()
}
Expand Down
7 changes: 3 additions & 4 deletions daemon/handlers.sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import (
"time"

"github.com/malamtime/cli/model"
"github.com/vmihailenco/msgpack/v5"
)

func handlePubSubSync(ctx context.Context, socketMsgPayload interface{}) error {
pb, err := msgpack.Marshal(socketMsgPayload)
pb, err := model.MsgpackEncode(socketMsgPayload)
if err != nil {
slog.Error("Failed to marshal the sync payload again for unmarshal", slog.Any("payload", socketMsgPayload))
return err
}

var syncMsg model.PostTrackArgs
err = msgpack.Unmarshal(pb, &syncMsg)
err = model.MsgpackDecode(pb, &syncMsg)
if err != nil {
slog.Error("Failed to parse sync payload", slog.Any("payload", socketMsgPayload))
return err
Expand Down Expand Up @@ -74,7 +73,7 @@ func handlePubSubSync(ctx context.Context, socketMsgPayload interface{}) error {
slog.Error("Failed to encrypt key", slog.Any("err", err))
}

buf, err := msgpack.Marshal(payload)
buf, err := model.MsgpackEncode(payload)

if err != nil {
slog.Error("Failed to marshal payload", slog.Any("err", err))
Expand Down
3 changes: 1 addition & 2 deletions daemon/handlers.sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"github.com/vmihailenco/msgpack/v5"
)

type SyncHandlerTestSuite struct {
Expand Down Expand Up @@ -71,7 +70,7 @@ func (s *SyncHandlerTestSuite) handleTrackEndpoint(w http.ResponseWriter, r *htt

// Decode request body
var trackArgs model.PostTrackArgs
if err := msgpack.NewDecoder(r.Body).Decode(&trackArgs); err != nil {
if err := model.MsgpackDecodeReader(r.Body, &trackArgs); err != nil {
http.Error(w, "Invalid request body", http.StatusBadRequest)
return
}
Expand Down
13 changes: 6 additions & 7 deletions daemon/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"github.com/vmihailenco/msgpack/v5"
)

type handlersTestSuite struct {
Expand Down Expand Up @@ -49,7 +48,7 @@ func (s *handlersTestSuite) TestSocketTopicProcessorValidSync() {
},
},
}
payload, err := msgpack.Marshal(socketMsg)
payload, err := model.MsgpackEncode(socketMsg)
assert.NoError(s.T(), err)

msg := message.NewMessage("test-uuid", payload)
Expand Down Expand Up @@ -91,7 +90,7 @@ func (s *handlersTestSuite) TestSocketTopicProcessorNonSync() {
},
},
}
payload, err := msgpack.Marshal(socketMsg)
payload, err := model.MsgpackEncode(socketMsg)
assert.NoError(s.T(), err)

msg := message.NewMessage("test-uuid", payload)
Expand All @@ -110,9 +109,9 @@ func (s *handlersTestSuite) TestSocketTopicProcessorInvalidPayload() {

socketMsg := SocketMessage{
Type: "sync",
Payload: []byte(`invalid json`),
Payload: model.PostTrackArgs{},
}
payload, err := msgpack.Marshal(socketMsg)
payload, err := model.MsgpackEncode(socketMsg)
assert.NoError(s.T(), err)

msg := message.NewMessage("test-uuid", payload)
Expand Down Expand Up @@ -140,7 +139,7 @@ func (s *handlersTestSuite) TestSocketTopicProcessorMultipleMessages() {
},
},
}
payload1, err := msgpack.Marshal(socketMsg1)
payload1, err := model.MsgpackEncode(socketMsg1)
assert.NoError(s.T(), err)

socketMsg2 := SocketMessage{
Expand All @@ -154,7 +153,7 @@ func (s *handlersTestSuite) TestSocketTopicProcessorMultipleMessages() {
},
},
}
payload2, err := msgpack.Marshal(socketMsg2)
payload2, err := model.MsgpackEncode(socketMsg2)
assert.NoError(s.T(), err)

msg1 := message.NewMessage("test-uuid-1", payload1)
Expand Down
11 changes: 5 additions & 6 deletions daemon/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/vmihailenco/msgpack/v5"
"github.com/malamtime/cli/model"
)

type SocketMessageType string
Expand All @@ -17,9 +17,9 @@ const (
)

type SocketMessage struct {
Type SocketMessageType `msgpack:"type"`
Type SocketMessageType `codec:"type"`
// if parse from buffer, it will be the map[any]any
Payload interface{} `msgpack:"payload"`
Payload model.PostTrackArgs `codec:"payload"`
}

type SocketHandler struct {
Expand Down Expand Up @@ -89,9 +89,8 @@ func (p *SocketHandler) acceptConnections() {

func (p *SocketHandler) handleConnection(conn net.Conn) {
defer conn.Close()
decoder := msgpack.NewDecoder(conn)
var msg SocketMessage
if err := decoder.Decode(&msg); err != nil {
if err := model.MsgpackDecodeReader(conn, &msg); err != nil {
slog.Error("Error decoding message", slog.Any("err", err))
return
}
Expand All @@ -102,7 +101,7 @@ func (p *SocketHandler) handleConnection(conn net.Conn) {
// case "track":
// p.handleTrack(conn, msg.Payload)
case SocketMessageTypeSync:
buf, err := msgpack.Marshal(msg)
buf, err := model.MsgpackEncode(msg)
if err != nil {
slog.Error("Error encoding message", slog.Any("err", err))
}
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.10.0
github.com/ugorji/go/codec v1.3.0
github.com/uptrace/uptrace-go v1.32.0
github.com/urfave/cli/v2 v2.27.4
github.com/vmihailenco/msgpack/v5 v5.4.1
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0
go.opentelemetry.io/otel v1.33.0
go.opentelemetry.io/otel/trace v1.33.0
Expand All @@ -39,8 +39,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/ugorji/go/codec v1.3.0 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -75,10 +75,6 @@ github.com/uptrace/uptrace-go v1.32.0 h1:j8fmeU5/m0Q4gX1FYlN9GpFrPnpuPUOeK8DVrm1
github.com/uptrace/uptrace-go v1.32.0/go.mod h1:ITT13kOzEZKnEqqK7WTEzh9dl7Ilbef/y3EIdv61T7Y=
github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8=
github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
Expand Down
16 changes: 8 additions & 8 deletions model/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ type Alias struct {
}

type importShellAliasRequest struct {
Aliases []string `json:"aliases" msgpack:"aliases"`
IsFullRefresh bool `json:"isFullRefresh" msgpack:"isFullRefresh"`
ShellType string `json:"shellType" msgpack:"shellType"`
FileLocation string `json:"fileLocation" msgpack:"fileLocation"`
Aliases []string `json:"aliases" codec:"aliases"`
IsFullRefresh bool `json:"isFullRefresh" codec:"isFullRefresh"`
ShellType string `json:"shellType" codec:"shellType"`
FileLocation string `json:"fileLocation" codec:"fileLocation"`

Hostname string `json:"hostname" msgpack:"hostname"`
Username string `json:"username" msgpack:"username"`
OS string `json:"os" msgpack:"os"`
OSVersion string `json:"osVersion" msgpack:"osVersion"`
Hostname string `json:"hostname" codec:"hostname"`
Username string `json:"username" codec:"username"`
OS string `json:"os" codec:"os"`
OSVersion string `json:"osVersion" codec:"osVersion"`
}

type importShellAliasResponse struct {
Expand Down
5 changes: 2 additions & 3 deletions model/api.base.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/sirupsen/logrus"
"github.com/vmihailenco/msgpack/v5"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

Expand All @@ -33,7 +32,7 @@ func SendHTTPRequest[T any, R any](opts HTTPRequestOptions[T, R]) error {
ctx, span := modelTracer.Start(opts.Context, "http.send")
defer span.End()

jsonData, err := msgpack.Marshal(opts.Payload)
jsonData, err := MsgpackEncode(opts.Payload)
if err != nil {
logrus.Errorln(err)
return err
Expand Down Expand Up @@ -108,7 +107,7 @@ func SendHTTPRequest[T any, R any](opts HTTPRequestOptions[T, R]) error {
return nil
}
if strings.Contains(contentType, "msgpack") {
err = msgpack.Unmarshal(buf, opts.Response)
err = MsgpackDecode(buf, opts.Response)
if err != nil {
logrus.Errorln("Failed to unmarshal response:", err)
return err
Expand Down
Loading
Loading