Files
3x-ui/internal/web/service/client_bulk_reset_reenable_test.go
T
n0ctal 7c183dbd97 fix(clients): surface bulk-reset auto-enable failures (#5763)
* fix(clients): surface bulk-reset auto-enable failures

BulkResetTraffic re-enables a disabled client before resetting its
traffic, but discarded the s.Update result with `_, _ =`, so a failed
re-enable was silent: the client stayed disabled with nothing logged,
unlike the single-client ResetTraffic path which already warns on the
same call. Check the error and log a warning to match, and add a
regression test covering BulkResetTraffic's previously-untested
re-enable path.

* ci: update Go toolchain for govulncheck

---------

Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
2026-07-08 20:53:42 +02:00

30 lines
1003 B
Go

package service
import "testing"
// TestBulkResetTraffic_ReenablesDisabledClient covers the re-enable branch of
// BulkResetTraffic: a disabled client whose traffic is bulk-reset must come back
// enabled with its counters zeroed, in all three enable locations. This is the
// path whose s.Update failure was previously swallowed silently.
func TestBulkResetTraffic_ReenablesDisabledClient(t *testing.T) {
setupBulkDB(t)
svc := &ClientService{}
inboundSvc := &InboundService{}
email := "reset-reenable@x"
ib := seedLocalDisabledClient(t, svc, 52010, "", email, 1000, 0, 600, 500)
affected, err := svc.BulkResetTraffic(inboundSvc, []string{email})
if err != nil {
t.Fatalf("BulkResetTraffic: %v", err)
}
if affected < 1 {
t.Fatalf("affected = %d, want >= 1", affected)
}
assertEnableEverywhere(t, svc, inboundSvc, ib.Id, email, true)
if tr := trafficOf(t, email); tr.Up != 0 || tr.Down != 0 {
t.Fatalf("%s: traffic after reset up=%d down=%d, want 0/0", email, tr.Up, tr.Down)
}
}