Fix float64 comparison in stats_helpers_test.go
package container
import (
- "github.com/docker/docker/api/types"
"testing"
+
+ "github.com/docker/docker/api/types"
+ "github.com/stretchr/testify/assert"
)
func TestCalculateMemUsageUnixNoCache(t *testing.T) {
@@ -13,9 +15,7 @@ func TestCalculateMemUsageUnixNoCache(t *testing.T) {
result := calculateMemUsageUnixNoCache(stats)
// Then
- if result != 100 {
- t.Errorf("mem = %d, want 100", result)
- }
+ assert.InDelta(t, 100.0, result, 1e-6)
}
func TestCalculateMemPercentUnixNoCache(t *testing.T) {
@@ -27,16 +27,10 @@ func TestCalculateMemPercentUnixNoCache(t *testing.T) {
// When and Then
t.Run("Limit is set", func(t *testing.T) {
result := calculateMemPercentUnixNoCache(someLimit, used)
- expected := float64(70.0)
- if result != expected {
- t.Errorf("percent = %f, want %f", result, expected)
- }
+ assert.InDelta(t, 70.0, result, 1e-6)
})
t.Run("No limit, no cgroup data", func(t *testing.T) {
result := calculateMemPercentUnixNoCache(noLimit, used)
- expected := float64(0.0)
- if result != expected {
- t.Errorf("percent = %f, want %f", result, expected)
- }
+ assert.InDelta(t, 0.0, result, 1e-6)
})
}
