check / check (push) Failing after 0s
Accumulating milestone branch. One squashed commit per closed issue; `next` is kept green and mergeable to `main` at any time without notice. Landed so far: - `chore: update golangci-lint to v2.12.2 with canonical config` (#54) — canonical v2-schema `.golangci.yml`, pins bumped in `Dockerfile` and `script/bootstrap`, tree at `0 issues.`. Three behaviour deltas are recorded in that PR's body: `Cache.StoreVariant` takes a context, `MetadataStorage.Store` no longer leaks temp files on failure, and the `signing_key` too-short error text gained a `value too short:` prefix. Sequencing for the milestone is tracked in #103. Reviewed-on: #105 Co-authored-by: clawbot <clawbot@noreply.example.org>
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package imgcache
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"testing"
|
|
)
|
|
|
|
func TestSizePercentSafeWithZeroFetchBytes(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Simulate the calculation from processAndStore
|
|
fetchBytes := int64(0)
|
|
outputSize := int64(100)
|
|
|
|
var sizePercent float64
|
|
if fetchBytes > 0 {
|
|
sizePercent = float64(outputSize) / float64(fetchBytes) * 100.0
|
|
}
|
|
|
|
// sizePercent should be 0, not Inf or NaN
|
|
if math.IsInf(sizePercent, 0) || math.IsNaN(sizePercent) {
|
|
t.Errorf("sizePercent = %f, should not be Inf/NaN", sizePercent)
|
|
}
|
|
|
|
// Should produce valid log output
|
|
result := fmt.Sprintf("%.1f%%", sizePercent)
|
|
if result != "0.0%" {
|
|
t.Errorf("formatted size ratio = %q, want %q", result, "0.0%")
|
|
}
|
|
}
|
|
|
|
func TestSizePercentNormalCase(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
fetchBytes := int64(1000)
|
|
outputSize := int64(500)
|
|
|
|
var sizePercent float64
|
|
if fetchBytes > 0 {
|
|
sizePercent = float64(outputSize) / float64(fetchBytes) * 100.0
|
|
}
|
|
|
|
if math.Abs(sizePercent-50.0) > 0.001 {
|
|
t.Errorf("sizePercent = %f, want 50.0", sizePercent)
|
|
}
|
|
}
|