aboutsummaryrefslogtreecommitdiffhomepage
path: root/metrics/metrics_test.go
diff options
context:
space:
mode:
authorCameron Moore <[email protected]>2022-05-25 21:14:37 -0500
committerBjørn Erik Pedersen <[email protected]>2022-05-26 10:39:29 +0200
commit6a5acd753abbd899547c89b369de71df639cce19 (patch)
tree2aca1bc7d9ea86129819db0f248fe83c95f9cd12 /metrics/metrics_test.go
parent805b21555e283c28a669943a36af6d6d699e9198 (diff)
downloadhugo-6a5acd753abbd899547c89b369de71df639cce19.tar.gz
hugo-6a5acd753abbd899547c89b369de71df639cce19.zip
metrics: Fix divide by zero error
Under certain conditions, `howSimilarString` could reach a divide-by- zero situation which causes bogus values to print in the cache potential column of the template hints output. This situation essentially causes a `int(math.NaN())` value to be returned and hilarity ensues thereafter.
Diffstat (limited to 'metrics/metrics_test.go')
-rw-r--r--metrics/metrics_test.go1
1 files changed, 1 insertions, 0 deletions
diff --git a/metrics/metrics_test.go b/metrics/metrics_test.go
index d8c3237f8..6e799a393 100644
--- a/metrics/metrics_test.go
+++ b/metrics/metrics_test.go
@@ -43,6 +43,7 @@ func TestSimilarPercentage(t *testing.T) {
c.Assert(howSimilar(template.HTML("Hugo Rules"), template.HTML("Hugo Rules")), qt.Equals, 100)
c.Assert(howSimilar(map[string]any{"a": 32, "b": 33}, map[string]any{"a": 32, "b": 33}), qt.Equals, 100)
c.Assert(howSimilar(map[string]any{"a": 32, "b": 33}, map[string]any{"a": 32, "b": 34}), qt.Equals, 0)
+ c.Assert(howSimilar("\n", ""), qt.Equals, 100)
}
type testStruct struct {