refactor: use shared mocks for tests

This commit is contained in:
talksik
2026-04-22 09:06:10 -07:00
parent 2e9ff742a0
commit 110f4594be
10 changed files with 304 additions and 174 deletions
-150
View File
@@ -1,150 +0,0 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: /Users/talksik/Documents/code/llink/go/genproto/aero/main_grpc.pb.go
//
// Generated by this command:
//
// mockgen -source=/Users/talksik/Documents/code/llink/go/genproto/aero/main_grpc.pb.go -destination=/Users/talksik/Documents/code/llink/go/internal/network/mocks/mock_aero.go -package=mocks
//
// Package mocks is a generated GoMock package.
package mocks
import (
context "context"
reflect "reflect"
pbaero "github.com/flowy-live/llink/genproto/aero"
gomock "go.uber.org/mock/gomock"
grpc "google.golang.org/grpc"
)
// MockPrimaryClient is a mock of PrimaryClient interface.
type MockPrimaryClient struct {
ctrl *gomock.Controller
recorder *MockPrimaryClientMockRecorder
isgomock struct{}
}
// MockPrimaryClientMockRecorder is the mock recorder for MockPrimaryClient.
type MockPrimaryClientMockRecorder struct {
mock *MockPrimaryClient
}
// NewMockPrimaryClient creates a new mock instance.
func NewMockPrimaryClient(ctrl *gomock.Controller) *MockPrimaryClient {
mock := &MockPrimaryClient{ctrl: ctrl}
mock.recorder = &MockPrimaryClientMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockPrimaryClient) EXPECT() *MockPrimaryClientMockRecorder {
return m.recorder
}
// ShootEmail mocks base method.
func (m *MockPrimaryClient) ShootEmail(ctx context.Context, in *pbaero.ShootEmailRequest, opts ...grpc.CallOption) (*pbaero.ShootEmailResponse, error) {
m.ctrl.T.Helper()
varargs := []any{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "ShootEmail", varargs...)
ret0, _ := ret[0].(*pbaero.ShootEmailResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ShootEmail indicates an expected call of ShootEmail.
func (mr *MockPrimaryClientMockRecorder) ShootEmail(ctx, in any, opts ...any) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]any{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ShootEmail", reflect.TypeOf((*MockPrimaryClient)(nil).ShootEmail), varargs...)
}
// MockPrimaryServer is a mock of PrimaryServer interface.
type MockPrimaryServer struct {
ctrl *gomock.Controller
recorder *MockPrimaryServerMockRecorder
isgomock struct{}
}
// MockPrimaryServerMockRecorder is the mock recorder for MockPrimaryServer.
type MockPrimaryServerMockRecorder struct {
mock *MockPrimaryServer
}
// NewMockPrimaryServer creates a new mock instance.
func NewMockPrimaryServer(ctrl *gomock.Controller) *MockPrimaryServer {
mock := &MockPrimaryServer{ctrl: ctrl}
mock.recorder = &MockPrimaryServerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockPrimaryServer) EXPECT() *MockPrimaryServerMockRecorder {
return m.recorder
}
// ShootEmail mocks base method.
func (m *MockPrimaryServer) ShootEmail(arg0 context.Context, arg1 *pbaero.ShootEmailRequest) (*pbaero.ShootEmailResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ShootEmail", arg0, arg1)
ret0, _ := ret[0].(*pbaero.ShootEmailResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ShootEmail indicates an expected call of ShootEmail.
func (mr *MockPrimaryServerMockRecorder) ShootEmail(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ShootEmail", reflect.TypeOf((*MockPrimaryServer)(nil).ShootEmail), arg0, arg1)
}
// mustEmbedUnimplementedPrimaryServer mocks base method.
func (m *MockPrimaryServer) mustEmbedUnimplementedPrimaryServer() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "mustEmbedUnimplementedPrimaryServer")
}
// mustEmbedUnimplementedPrimaryServer indicates an expected call of mustEmbedUnimplementedPrimaryServer.
func (mr *MockPrimaryServerMockRecorder) mustEmbedUnimplementedPrimaryServer() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "mustEmbedUnimplementedPrimaryServer", reflect.TypeOf((*MockPrimaryServer)(nil).mustEmbedUnimplementedPrimaryServer))
}
// MockUnsafePrimaryServer is a mock of UnsafePrimaryServer interface.
type MockUnsafePrimaryServer struct {
ctrl *gomock.Controller
recorder *MockUnsafePrimaryServerMockRecorder
isgomock struct{}
}
// MockUnsafePrimaryServerMockRecorder is the mock recorder for MockUnsafePrimaryServer.
type MockUnsafePrimaryServerMockRecorder struct {
mock *MockUnsafePrimaryServer
}
// NewMockUnsafePrimaryServer creates a new mock instance.
func NewMockUnsafePrimaryServer(ctrl *gomock.Controller) *MockUnsafePrimaryServer {
mock := &MockUnsafePrimaryServer{ctrl: ctrl}
mock.recorder = &MockUnsafePrimaryServerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockUnsafePrimaryServer) EXPECT() *MockUnsafePrimaryServerMockRecorder {
return m.recorder
}
// mustEmbedUnimplementedPrimaryServer mocks base method.
func (m *MockUnsafePrimaryServer) mustEmbedUnimplementedPrimaryServer() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "mustEmbedUnimplementedPrimaryServer")
}
// mustEmbedUnimplementedPrimaryServer indicates an expected call of mustEmbedUnimplementedPrimaryServer.
func (mr *MockUnsafePrimaryServerMockRecorder) mustEmbedUnimplementedPrimaryServer() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "mustEmbedUnimplementedPrimaryServer", reflect.TypeOf((*MockUnsafePrimaryServer)(nil).mustEmbedUnimplementedPrimaryServer))
}
+1 -4
View File
@@ -57,10 +57,7 @@ type serviceImpl struct {
repo repository
aeroSvc pbaero.PrimaryClient
billingSvc billing.Service
// fs mirrors network membership into humans/{humanId}.networks so
// Firestore security rules can check membership at rule-eval time.
// May be nil in services that never mutate membership (pusher).
fs *firestore.Client
fs *firestore.Client
}
func NewService(pool *pgxpool.Pool, aeroSvc pbaero.PrimaryClient, billingSvc billing.Service, fs *firestore.Client) Service {
+2 -2
View File
@@ -8,8 +8,8 @@ import (
pbaero "github.com/flowy-live/llink/genproto/aero"
"github.com/flowy-live/llink/internal/billing"
"github.com/flowy-live/llink/internal/network"
"github.com/flowy-live/llink/internal/network/mocks"
"github.com/flowy-live/llink/internal/testhelper"
"github.com/flowy-live/llink/internal/testhelper/mocks/aero"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
@@ -27,7 +27,7 @@ func TestMain(m *testing.M) {
func newTestService(t *testing.T) network.Service {
ctrl := gomock.NewController(t)
mockAero := mocks.NewMockPrimaryClient(ctrl)
mockAero := aero.NewMockPrimaryClient(ctrl)
mockAero.EXPECT().
ShootEmail(gomock.Any(), gomock.Any()).
Return(&pbaero.ShootEmailResponse{}, nil).