fix: add groupExistenceBatchReader interface and update test stub for release branch compatibility

This commit is contained in:
erio
2026-03-01 15:53:45 +08:00
parent 2268e93aec
commit d4231150a9
2 changed files with 18 additions and 16 deletions

View File

@@ -336,6 +336,10 @@ type ProxyExitInfoProber interface {
ProbeProxy(ctx context.Context, proxyURL string) (*ProxyExitInfo, int64, error) ProbeProxy(ctx context.Context, proxyURL string) (*ProxyExitInfo, int64, error)
} }
type groupExistenceBatchReader interface {
ExistsByIDs(ctx context.Context, ids []int64) (map[int64]bool, error)
}
type proxyQualityTarget struct { type proxyQualityTarget struct {
Target string Target string
URL string URL string

View File

@@ -15,6 +15,7 @@ type accountRepoStubForBulkUpdate struct {
bulkUpdateErr error bulkUpdateErr error
bulkUpdateIDs []int64 bulkUpdateIDs []int64
bindGroupErrByID map[int64]error bindGroupErrByID map[int64]error
bindGroupsCalls []int64
getByIDsAccounts []*Account getByIDsAccounts []*Account
getByIDsErr error getByIDsErr error
getByIDsCalled bool getByIDsCalled bool
@@ -22,6 +23,8 @@ type accountRepoStubForBulkUpdate struct {
getByIDAccounts map[int64]*Account getByIDAccounts map[int64]*Account
getByIDErrByID map[int64]error getByIDErrByID map[int64]error
getByIDCalled []int64 getByIDCalled []int64
listByGroupData map[int64][]Account
listByGroupErr map[int64]error
} }
func (s *accountRepoStubForBulkUpdate) BulkUpdate(_ context.Context, ids []int64, _ AccountBulkUpdate) (int64, error) { func (s *accountRepoStubForBulkUpdate) BulkUpdate(_ context.Context, ids []int64, _ AccountBulkUpdate) (int64, error) {
@@ -33,12 +36,23 @@ func (s *accountRepoStubForBulkUpdate) BulkUpdate(_ context.Context, ids []int64
} }
func (s *accountRepoStubForBulkUpdate) BindGroups(_ context.Context, accountID int64, _ []int64) error { func (s *accountRepoStubForBulkUpdate) BindGroups(_ context.Context, accountID int64, _ []int64) error {
s.bindGroupsCalls = append(s.bindGroupsCalls, accountID)
if err, ok := s.bindGroupErrByID[accountID]; ok { if err, ok := s.bindGroupErrByID[accountID]; ok {
return err return err
} }
return nil return nil
} }
func (s *accountRepoStubForBulkUpdate) ListByGroup(_ context.Context, groupID int64) ([]Account, error) {
if err, ok := s.listByGroupErr[groupID]; ok {
return nil, err
}
if rows, ok := s.listByGroupData[groupID]; ok {
return rows, nil
}
return nil, nil
}
func (s *accountRepoStubForBulkUpdate) GetByIDs(_ context.Context, ids []int64) ([]*Account, error) { func (s *accountRepoStubForBulkUpdate) GetByIDs(_ context.Context, ids []int64) ([]*Account, error) {
s.getByIDsCalled = true s.getByIDsCalled = true
s.getByIDsIDs = append([]int64{}, ids...) s.getByIDsIDs = append([]int64{}, ids...)
@@ -106,22 +120,6 @@ func TestAdminService_BulkUpdateAccounts_PartialFailureIDs(t *testing.T) {
require.Len(t, result.Results, 3) require.Len(t, result.Results, 3)
} }
func TestAdminService_BulkUpdateAccounts_NilGroupRepoReturnsError(t *testing.T) {
repo := &accountRepoStubForBulkUpdate{}
svc := &adminServiceImpl{accountRepo: repo}
groupIDs := []int64{10}
input := &BulkUpdateAccountsInput{
AccountIDs: []int64{1},
GroupIDs: &groupIDs,
}
result, err := svc.BulkUpdateAccounts(context.Background(), input)
require.Nil(t, result)
require.Error(t, err)
require.Contains(t, err.Error(), "group repository not configured")
}
// TestAdminService_BulkUpdateAccounts_MixedChannelPreCheckBlocksOnExistingConflict verifies // TestAdminService_BulkUpdateAccounts_MixedChannelPreCheckBlocksOnExistingConflict verifies
// that the global pre-check detects a conflict with existing group members and returns an // that the global pre-check detects a conflict with existing group members and returns an
// error before any DB write is performed. // error before any DB write is performed.