From 3c78bc775c21c238eb534e3d2631695b4c09a215 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Sat, 13 May 2017 23:23:15 +0000 Subject: [PATCH] Fix float64 comparison in stats_helpers_test.go Signed-off-by: Akihiro Suda --- cli/command/container/stats_helpers_test.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/cli/command/container/stats_helpers_test.go b/cli/command/container/stats_helpers_test.go index 589ee8f66f..0425a3ba13 100644 --- a/cli/command/container/stats_helpers_test.go +++ b/cli/command/container/stats_helpers_test.go @@ -1,8 +1,10 @@ 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) }) }