-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ARCO-282): Separate callbacker #642
- Loading branch information
1 parent
c4c1a23
commit fb6a5e8
Showing
3 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
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) { | ||
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())) | ||
}) | ||
} | ||
|
||
} |