style(tests): clear the editor diagnostics in the service tests

The config scale benchmark used the b.N loop that gopls flags for modernization; it now uses b.Loop, which also makes its ResetTimer and StopTimer calls redundant. assertInboundClientGroup and seedUsageHistoryClient each took a parameter they never read, so the parameters and the arguments passed for them are gone.
This commit is contained in:
Sanaei
2026-11-29 11:31:20 +03:30
parent 408fd682f5
commit 6d9a23feb5
3 changed files with 17 additions and 20 deletions
@@ -387,20 +387,20 @@ func TestClientGroup_RenameAndDeleteFollowCanonicalizedJSONCase(t *testing.T) {
if rec.Group != "VIP" {
t.Fatalf("client group = %q, want canonical VIP", rec.Group)
}
assertInboundClientGroup(t, db, ib.Id, "case@x", "vip")
assertInboundClientGroup(t, db, ib.Id, "vip")
if _, err := svc.UpdateGroup("VIP", "Gold", nil); err != nil {
t.Fatalf("UpdateGroup: %v", err)
}
assertInboundClientGroup(t, db, ib.Id, "case@x", "Gold")
assertInboundClientGroup(t, db, ib.Id, "Gold")
if _, err := svc.DeleteGroup("Gold"); err != nil {
t.Fatalf("DeleteGroup: %v", err)
}
assertInboundClientGroup(t, db, ib.Id, "case@x", "")
assertInboundClientGroup(t, db, ib.Id, "")
}
func assertInboundClientGroup(t *testing.T, db *gorm.DB, inboundID int, email, want string) {
func assertInboundClientGroup(t *testing.T, db *gorm.DB, inboundID int, want string) {
t.Helper()
var settings string
if err := db.Model(&model.Inbound{}).Where("id = ?", inboundID).Pluck("settings", &settings).Error; err != nil {
@@ -12,7 +12,7 @@ import (
// seedUsageHistoryClient seeds a local VLESS inbound hosting one client and a
// live traffic row with the given counters.
func seedUsageHistoryClient(t *testing.T, inboundSvc *InboundService, email, uid string, up, down int64) *model.Inbound {
func seedUsageHistoryClient(t *testing.T, email, uid string, up, down int64) *model.Inbound {
t.Helper()
setupBulkDB(t)
svc := &ClientService{}
@@ -90,7 +90,7 @@ func TestEveryResetPathArchivesTheWindowItCloses(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
inbounds, clients := &InboundService{}, &ClientService{}
ib := seedUsageHistoryClient(t, inbounds, email, "44444444-1111-4111-8111-111111111111", 100, 200)
ib := seedUsageHistoryClient(t, email, "44444444-1111-4111-8111-111111111111", 100, 200)
if err := tc.reset(inbounds, clients, ib); err != nil {
t.Fatal(err)
}
@@ -115,7 +115,7 @@ func TestEveryResetPathArchivesTheWindowItCloses(t *testing.T) {
func TestWindowsPastTheCapFoldWithoutChangingLifetime(t *testing.T) {
const email = "capped@example.test"
inbounds, clients := &InboundService{}, &ClientService{}
ib := seedUsageHistoryClient(t, inbounds, email, "12121212-1111-4111-8111-111111111111", 100, 200)
ib := seedUsageHistoryClient(t, email, "12121212-1111-4111-8111-111111111111", 100, 200)
db := database.GetDB()
seeded := make([]model.ClientTrafficWindow, 0, clientTrafficWindowKeep)
for i := range clientTrafficWindowKeep {
@@ -169,7 +169,7 @@ func TestWindowsPastTheCapFoldWithoutChangingLifetime(t *testing.T) {
func TestLifetimeCountsTheOpenWindow(t *testing.T) {
const email = "open-win@example.test"
inbounds, clients := &InboundService{}, &ClientService{}
ib := seedUsageHistoryClient(t, inbounds, email, "17171717-1111-4111-8111-111111111111", 100, 200)
ib := seedUsageHistoryClient(t, email, "17171717-1111-4111-8111-111111111111", 100, 200)
if _, err := inbounds.ResetClientTraffic(ib.Id, email); err != nil {
t.Fatal(err)
}
@@ -191,7 +191,7 @@ func TestLifetimeCountsTheOpenWindow(t *testing.T) {
func TestChangeLogKeepsTheNewestRowsPerClient(t *testing.T) {
const email, other = "chatty@example.test", "quiet@example.test"
inbounds, clients := &InboundService{}, &ClientService{}
seedUsageHistoryClient(t, inbounds, email, "13131313-1111-4111-8111-111111111111", 0, 0)
seedUsageHistoryClient(t, email, "13131313-1111-4111-8111-111111111111", 0, 0)
db := database.GetDB()
seeded := make([]model.ClientChangeLog, 0, clientChangeLogKeep+1)
for i := range clientChangeLogKeep {
@@ -226,7 +226,7 @@ func TestChangeLogKeepsTheNewestRowsPerClient(t *testing.T) {
func TestBotAndBulkEditsAreLoggedWithTheirSource(t *testing.T) {
const email = "edited@example.test"
inbounds, clients := &InboundService{}, &ClientService{}
seedUsageHistoryClient(t, inbounds, email, "14141414-1111-4111-8111-111111111111", 0, 0)
seedUsageHistoryClient(t, email, "14141414-1111-4111-8111-111111111111", 0, 0)
// The bulk add skips an unlimited client, so the bot sets a limit first.
if _, err := clients.ResetClientTrafficLimitByEmail(inbounds, email, 1); err != nil {
@@ -254,7 +254,7 @@ func TestBotAndBulkEditsAreLoggedWithTheirSource(t *testing.T) {
func TestHistoryOfADeletedClientIsReaped(t *testing.T) {
const gone, kept = "gone@example.test", "kept@example.test"
inbounds, clients := &InboundService{}, &ClientService{}
seedUsageHistoryClient(t, inbounds, gone, "15151515-1111-4111-8111-111111111111", 0, 0)
seedUsageHistoryClient(t, gone, "15151515-1111-4111-8111-111111111111", 0, 0)
stays := model.Client{Email: kept, ID: "16161616-1111-4111-8111-111111111111", SubID: kept, Enable: true}
ib := mkInbound(t, 54506, model.VLESS, clientsSettings(t, []model.Client{stays}))
if err := clients.SyncInbound(nil, ib.Id, []model.Client{stays}); err != nil {
@@ -323,7 +323,7 @@ func TestReapSparesAnEmailClaimedAfterItWasListed(t *testing.T) {
// Bulk reset archives only the rows that actually carried usage.
func TestBulkResetArchivesUsedWindowsOnly(t *testing.T) {
inboundSvc := &InboundService{}
seedUsageHistoryClient(t, inboundSvc, "bulk-used@example.test", "55555555-2222-4222-8222-222222222222", 10, 5)
seedUsageHistoryClient(t, "bulk-used@example.test", "55555555-2222-4222-8222-222222222222", 10, 5)
svc := &ClientService{}
// A second zero-usage client on its own inbound.
@@ -404,7 +404,7 @@ func TestAutoRenewArchivesRenewWindowAndLogsExpiry(t *testing.T) {
// no-op save logs nothing.
func TestUpdateLogsChangedFieldsOnly(t *testing.T) {
inboundSvc := &InboundService{}
seedUsageHistoryClient(t, inboundSvc, "upd-log@example.test", "99999999-6666-4666-8666-666666666666", 0, 0)
seedUsageHistoryClient(t, "upd-log@example.test", "99999999-6666-4666-8666-666666666666", 0, 0)
svc := &ClientService{}
rec, err := svc.GetRecordByEmail(nil, "upd-log@example.test")
@@ -448,7 +448,7 @@ func TestUpdateLogsChangedFieldsOnly(t *testing.T) {
// Bulk enable/disable logs an "enable" row only for the clients that flipped.
func TestBulkSetEnableLogsOnlyFlippedClients(t *testing.T) {
inboundSvc := &InboundService{}
seedUsageHistoryClient(t, inboundSvc, "bulk-en-a@example.test", "aaaaaaaa-7777-4777-8777-777777777777", 0, 0)
seedUsageHistoryClient(t, "bulk-en-a@example.test", "aaaaaaaa-7777-4777-8777-777777777777", 0, 0)
svc := &ClientService{}
clientB := model.Client{Email: "bulk-en-b@example.test", ID: "bbbbbbbb-8888-4888-8888-888888888888", SubID: "bulk-en-b@example.test", Enable: true}
ib2 := mkInbound(t, 54505, model.VLESS, clientsSettings(t, []model.Client{clientB}))
@@ -479,7 +479,7 @@ func TestBulkSetEnableLogsOnlyFlippedClients(t *testing.T) {
func TestRenameMigratesClientHistory(t *testing.T) {
const oldEmail, newEmail = "old-name@example.test", "new-name@example.test"
inboundSvc := &InboundService{}
ib := seedUsageHistoryClient(t, inboundSvc, oldEmail, "cccccccc-9999-4999-8999-999999999999", 7, 9)
ib := seedUsageHistoryClient(t, oldEmail, "cccccccc-9999-4999-8999-999999999999", 7, 9)
svc := &ClientService{}
same := model.Client{Email: oldEmail, ID: "cccccccc-9999-4999-8999-999999999999", SubID: oldEmail, Enable: true}
second := mkInbound(t, 54507, model.VLESS, clientsSettings(t, []model.Client{same}))
@@ -555,8 +555,7 @@ func TestRenameOfAnUnattachedClientMigratesItsHistory(t *testing.T) {
// GetUsageHistory must report the node's own accumulated up/down, separated.
func TestGetUsageHistoryReportsNodeUsage(t *testing.T) {
inboundSvc := &InboundService{}
seedUsageHistoryClient(t, inboundSvc, "node-usage@example.test", "eeeeeeee-bbbb-4bbb-8bbb-bbbbbbbbbbbb", 0, 0)
seedUsageHistoryClient(t, "node-usage@example.test", "eeeeeeee-bbbb-4bbb-8bbb-bbbbbbbbbbbb", 0, 0)
db := database.GetDB()
node := &model.Node{
@@ -33,13 +33,11 @@ func BenchmarkGetXrayConfigDisabledClients(b *testing.B) {
}
svc := &XrayService{}
b.ReportAllocs()
b.ResetTimer()
for range b.N {
for b.Loop() {
if _, err := svc.GetXrayConfig(); err != nil {
b.Fatal(err)
}
}
b.StopTimer()
const marker = "disabled-client benchmark log boundary"
logger.Info(marker)
if _, err := svc.GetXrayConfig(); err != nil {