Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// diskCapacityUploadPayload shapes the 507 body the stream and URL upload
|
||||
// routes emit when a secondary disk's LimitGb ceiling binds. The panel/relay
|
||||
// passthrough (isNodeQuota507) and the operator-facing message both depend on
|
||||
// this exact shape, so pin it.
|
||||
func TestDiskCapacityUploadPayload(t *testing.T) {
|
||||
p := diskCapacityUploadPayload(3*1024*1024*1024, 5*1024*1024*1024, 2*1024*1024*1024+7)
|
||||
if p["error"] != "disk_capacity_exceeded" {
|
||||
t.Fatalf("error code = %v, want disk_capacity_exceeded", p["error"])
|
||||
}
|
||||
if p["usedBytes"] != int64(3*1024*1024*1024) || p["limitBytes"] != int64(5*1024*1024*1024) {
|
||||
t.Fatalf("used/limit bytes mismatch: %v", p)
|
||||
}
|
||||
if p["remainingBytes"] != int64(2*1024*1024*1024) {
|
||||
t.Fatalf("remainingBytes = %v, want 2GiB", p["remainingBytes"])
|
||||
}
|
||||
if p["incomingBytes"] != int64(2*1024*1024*1024+7) {
|
||||
t.Fatalf("incomingBytes = %v, want the raw incoming estimate", p["incomingBytes"])
|
||||
}
|
||||
if msg, _ := p["message"].(string); !strings.Contains(msg, "capacity") {
|
||||
t.Fatalf("message %q must mention the disk capacity", msg)
|
||||
}
|
||||
|
||||
// Negative inputs clamp to zero instead of leaking into the JSON.
|
||||
neg := diskCapacityUploadPayload(-5, 10, -3)
|
||||
if neg["usedBytes"] != int64(0) || neg["incomingBytes"] != int64(0) {
|
||||
t.Fatalf("negative inputs must clamp to 0: %v", neg)
|
||||
}
|
||||
// Over-full disk: remaining clamps to zero, never negative.
|
||||
full := diskCapacityUploadPayload(20, 10, 1)
|
||||
if full["remainingBytes"] != int64(0) {
|
||||
t.Fatalf("remainingBytes must clamp to 0 on an over-full disk, got %v", full["remainingBytes"])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user