Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRebaseInfluxMakesTheNewestLineNowAndKeepsSpacing(t *testing.T) {
|
|
in := "m,host=a v=1 1000000000000000000\n# c\nm,host=a v=2 1000000060000000000\n"
|
|
now := time.Unix(2_000_000_000, 0)
|
|
out, n, err := rebaseInflux(in, now)
|
|
if err != nil || n != 2 {
|
|
t.Fatalf("n=%d err=%v", n, err)
|
|
}
|
|
want := "m,host=a v=1 1999999940000000000\nm,host=a v=2 2000000000000000000\n"
|
|
if out != want {
|
|
t.Fatalf("got %q want %q", out, want)
|
|
}
|
|
if _, _, err := rebaseInflux("\n# only comments\n", now); err == nil {
|
|
t.Fatal("empty input accepted")
|
|
}
|
|
if !strings.Contains(out, "host=a") {
|
|
t.Fatal("tags lost")
|
|
}
|
|
}
|
|
|
|
func TestProxmoxMockAuthShape(t *testing.T) {
|
|
for h, want := range map[string]bool{
|
|
"PVEAPIToken=root@pam!nmon=s3cret": true, "PVEAPIToken=root@pam!nmon=": false, "Bearer x": false, "": false,
|
|
} {
|
|
if validPVEAuth(h, "") != want {
|
|
t.Errorf("%q: want %v", h, want)
|
|
}
|
|
}
|
|
if validPVEAuth("PVEAPIToken=a@b!c=other", "s3cret") {
|
|
t.Error("wrong secret accepted")
|
|
}
|
|
}
|
|
|
|
func TestLongSamplesCarryVersionedHourlyAndFiveMinuteSeries(t *testing.T) {
|
|
end := time.Date(2026, 10, 20, 12, 0, 0, 0, time.UTC)
|
|
s := longSamples("d", "I", end, 1, 1, map[string]float64{"in": 8e6})
|
|
var h, f int
|
|
for _, x := range s {
|
|
switch x.Name {
|
|
case "nmon_if_rate_bps_5m":
|
|
f++
|
|
default:
|
|
h++
|
|
}
|
|
}
|
|
if f != 288 || h < 2*28*24 {
|
|
t.Fatalf("5m=%d hourly=%d", f, h)
|
|
}
|
|
if s[0].Labels[3].Name != "v" || s[0].Labels[3].Value != "202610001" {
|
|
t.Fatalf("labels %+v", s[0].Labels)
|
|
}
|
|
}
|