refactor: unit testable units and cleaner dep injection
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: ./service.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -source ./service.go -destination ./mocks/service.go
|
||||
//
|
||||
|
||||
// Package mock_billing is a generated GoMock package.
|
||||
package mock_billing
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
time "time"
|
||||
|
||||
billing "github.com/flowy-live/llink/internal/billing"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockService is a mock of Service interface.
|
||||
type MockService struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockServiceMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockServiceMockRecorder is the mock recorder for MockService.
|
||||
type MockServiceMockRecorder struct {
|
||||
mock *MockService
|
||||
}
|
||||
|
||||
// NewMockService creates a new mock instance.
|
||||
func NewMockService(ctrl *gomock.Controller) *MockService {
|
||||
mock := &MockService{ctrl: ctrl}
|
||||
mock.recorder = &MockServiceMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockService) EXPECT() *MockServiceMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// CreateCheckoutSession mocks base method.
|
||||
func (m *MockService) CreateCheckoutSession(ctx context.Context, p billing.CheckoutParams) (string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CreateCheckoutSession", ctx, p)
|
||||
ret0, _ := ret[0].(string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// CreateCheckoutSession indicates an expected call of CreateCheckoutSession.
|
||||
func (mr *MockServiceMockRecorder) CreateCheckoutSession(ctx, p any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateCheckoutSession", reflect.TypeOf((*MockService)(nil).CreateCheckoutSession), ctx, p)
|
||||
}
|
||||
|
||||
// CreatePortalSession mocks base method.
|
||||
func (m *MockService) CreatePortalSession(ctx context.Context, networkID string) (string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CreatePortalSession", ctx, networkID)
|
||||
ret0, _ := ret[0].(string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// CreatePortalSession indicates an expected call of CreatePortalSession.
|
||||
func (mr *MockServiceMockRecorder) CreatePortalSession(ctx, networkID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreatePortalSession", reflect.TypeOf((*MockService)(nil).CreatePortalSession), ctx, networkID)
|
||||
}
|
||||
|
||||
// GetStatus mocks base method.
|
||||
func (m *MockService) GetStatus(ctx context.Context, networkID string) (*billing.Status, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetStatus", ctx, networkID)
|
||||
ret0, _ := ret[0].(*billing.Status)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetStatus indicates an expected call of GetStatus.
|
||||
func (mr *MockServiceMockRecorder) GetStatus(ctx, networkID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStatus", reflect.TypeOf((*MockService)(nil).GetStatus), ctx, networkID)
|
||||
}
|
||||
|
||||
// GetUsage mocks base method.
|
||||
func (m *MockService) GetUsage(ctx context.Context, networkID string) (*billing.Usage, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetUsage", ctx, networkID)
|
||||
ret0, _ := ret[0].(*billing.Usage)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetUsage indicates an expected call of GetUsage.
|
||||
func (mr *MockServiceMockRecorder) GetUsage(ctx, networkID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsage", reflect.TypeOf((*MockService)(nil).GetUsage), ctx, networkID)
|
||||
}
|
||||
|
||||
// HandleWebhook mocks base method.
|
||||
func (m *MockService) HandleWebhook(ctx context.Context, payload []byte, signature string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "HandleWebhook", ctx, payload, signature)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// HandleWebhook indicates an expected call of HandleWebhook.
|
||||
func (mr *MockServiceMockRecorder) HandleWebhook(ctx, payload, signature any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HandleWebhook", reflect.TypeOf((*MockService)(nil).HandleWebhook), ctx, payload, signature)
|
||||
}
|
||||
|
||||
// IncrementDailyUsage mocks base method.
|
||||
func (m *MockService) IncrementDailyUsage(ctx context.Context, networkID string, at time.Time) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "IncrementDailyUsage", ctx, networkID, at)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// IncrementDailyUsage indicates an expected call of IncrementDailyUsage.
|
||||
func (mr *MockServiceMockRecorder) IncrementDailyUsage(ctx, networkID, at any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IncrementDailyUsage", reflect.TypeOf((*MockService)(nil).IncrementDailyUsage), ctx, networkID, at)
|
||||
}
|
||||
|
||||
// SyncSeats mocks base method.
|
||||
func (m *MockService) SyncSeats(ctx context.Context, networkID string, seats int) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SyncSeats", ctx, networkID, seats)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SyncSeats indicates an expected call of SyncSeats.
|
||||
func (mr *MockServiceMockRecorder) SyncSeats(ctx, networkID, seats any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncSeats", reflect.TypeOf((*MockService)(nil).SyncSeats), ctx, networkID, seats)
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package billing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Noop returns a billing service for binaries that depend on network.Service
|
||||
// but never mutate membership (jobs, pusher). Stripe isn't configured.
|
||||
func Noop() Service { return noopService{} }
|
||||
|
||||
type noopService struct{}
|
||||
|
||||
var errNoopBilling = errors.New("billing: not configured in this process")
|
||||
|
||||
func (noopService) GetStatus(context.Context, string) (*Status, error) {
|
||||
return nil, errNoopBilling
|
||||
}
|
||||
func (noopService) CreateCheckoutSession(context.Context, CheckoutParams) (string, error) {
|
||||
return "", errNoopBilling
|
||||
}
|
||||
func (noopService) CreatePortalSession(context.Context, string) (string, error) {
|
||||
return "", errNoopBilling
|
||||
}
|
||||
func (noopService) SyncSeats(context.Context, string, int) error { return nil }
|
||||
func (noopService) HandleWebhook(context.Context, []byte, string) error { return errNoopBilling }
|
||||
func (noopService) GetUsage(context.Context, string) (*Usage, error) {
|
||||
return nil, errNoopBilling
|
||||
}
|
||||
func (noopService) IncrementDailyUsage(context.Context, string, time.Time) error {
|
||||
return errNoopBilling
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
stripesub "github.com/stripe/stripe-go/v85/subscription"
|
||||
)
|
||||
|
||||
//go:generate mockgen -source ./service.go -destination ./mocks/service.go
|
||||
|
||||
type Service interface {
|
||||
GetStatus(ctx context.Context, networkID string) (*Status, error)
|
||||
CreateCheckoutSession(ctx context.Context, p CheckoutParams) (url string, err error)
|
||||
|
||||
Reference in New Issue
Block a user