mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/storage/bun/paginate"
|
|
"github.com/hanzo-fi/payments/internal/connectors/engine"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/hanzo-fi/payments/internal/storage"
|
|
"github.com/stretchr/testify/require"
|
|
gomock "go.uber.org/mock/gomock"
|
|
)
|
|
|
|
func TestPoolsList(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
store := storage.NewMockStorage(ctrl)
|
|
eng := engine.NewMockEngine(ctrl)
|
|
|
|
s := New(store, eng, false)
|
|
|
|
tests := []struct {
|
|
name string
|
|
err error
|
|
expectedError error
|
|
}{
|
|
{
|
|
name: "success",
|
|
err: nil,
|
|
expectedError: nil,
|
|
},
|
|
{
|
|
name: "storage error not found",
|
|
err: storage.ErrNotFound,
|
|
expectedError: newStorageError(storage.ErrNotFound, "cannot list pools"),
|
|
},
|
|
{
|
|
name: "other error",
|
|
err: fmt.Errorf("error"),
|
|
expectedError: newStorageError(fmt.Errorf("error"), "cannot list pools"),
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
query := storage.ListPoolsQuery{}
|
|
store.EXPECT().PoolsList(gomock.Any(), query).Return(&paginate.Cursor[models.Pool]{}, test.err)
|
|
_, err := s.PoolsList(context.Background(), query)
|
|
if test.expectedError == nil {
|
|
require.NoError(t, err)
|
|
} else {
|
|
require.Equal(t, test.expectedError, err)
|
|
}
|
|
})
|
|
}
|
|
}
|