mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 06:16:37 +08:00
3187934f72
- Scan ClickHouse count()/countIf() aggregates as uint64 before int64 conversion - Fix access log list count, region stats, and delete pre-count queries - Aggregate dashboard 24h traffic totals from hourly trend buckets - Show current hour value in traffic trend chart summary - Rename docker-compose service to openflare - Remove redundant config preview section from performance page
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package analytics
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
func TestSafeInt64Count(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
count uint64
|
|
want int64
|
|
}{
|
|
{name: "zero", count: 0, want: 0},
|
|
{name: "small", count: 42, want: 42},
|
|
{name: "max int64", count: math.MaxInt64, want: math.MaxInt64},
|
|
{name: "overflow clamps", count: math.MaxUint64, want: math.MaxInt64},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := safeInt64Count(tt.count); got != tt.want {
|
|
t.Fatalf("safeInt64Count(%d) = %d, want %d", tt.count, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSafeUint64Count(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
count int64
|
|
want uint64
|
|
}{
|
|
{name: "zero", count: 0, want: 0},
|
|
{name: "positive", count: 42, want: 42},
|
|
{name: "negative clamps", count: -1, want: 0},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := safeUint64Count(tt.count); got != tt.want {
|
|
t.Fatalf("safeUint64Count(%d) = %d, want %d", tt.count, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
} |