Skip to content

Commit

Permalink
refactor(ARCO-282): Separate callbacker #642
Browse files Browse the repository at this point in the history
  • Loading branch information
shotasilagadzetaal committed Nov 12, 2024
1 parent c4c1a23 commit fb6a5e8
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 0 deletions.
145 changes: 145 additions & 0 deletions internal/callbacker/callbacker_api/callbacker_api_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/callbacker/callbacker_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ package callbacker

// from callbacker.go
//go:generate moq -out ./callbacker_mock.go ./ SenderI

//go:generate moq -out ./callbacker_api/callbacker_api_client_mock.go ./callbacker_api/ CallbackerAPIClient
76 changes: 76 additions & 0 deletions pkg/callbacker/callbacker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package callbacker

import (
"context"
"log/slog"
"os"
"testing"

"github.com/bitcoin-sv/arc/internal/callbacker/callbacker_api"
"github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api"
"github.com/bitcoin-sv/arc/internal/metamorph/store"
"github.com/libsv/go-p2p/chaincfg/chainhash"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
)

func TestSendCallback(t *testing.T) {

Check failure on line 18 in pkg/callbacker/callbacker_test.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

empty-lines: extra empty line at the end of a block (revive)
tt := []struct {
name string
expectedCalls int
err error
data *store.Data
}{
{
name: "empty callbacks",
expectedCalls: 0,
data: &store.Data{
Status: metamorph_api.Status_UNKNOWN,
Hash: &chainhash.Hash{},
Callbacks: []store.Callback{},
},
},
{
name: "empty url",
expectedCalls: 0,

data: &store.Data{
Status: metamorph_api.Status_UNKNOWN,
Hash: &chainhash.Hash{},
Callbacks: []store.Callback{
{
CallbackURL: "",
},
},
},
},
{
name: "expected call",
expectedCalls: 1,
data: &store.Data{
Status: metamorph_api.Status_UNKNOWN,
Hash: &chainhash.Hash{},
Callbacks: []store.Callback{
{
CallbackURL: "http://someurl.comg",
},
},
},
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
apiClient := &callbacker_api.CallbackerAPIClientMock{
SendCallbackFunc: func(_ context.Context, in *callbacker_api.SendCallbackRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {

Check failure on line 66 in pkg/callbacker/callbacker_test.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
return nil, nil
},
}
grpcCallbacker := NewGrpcCallbacker(apiClient, slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})))
grpcCallbacker.SendCallback(context.Background(), tc.data)
require.Equal(t, tc.expectedCalls, len(apiClient.SendCallbackCalls()))
})
}

}

0 comments on commit fb6a5e8

Please sign in to comment.