Skip to content

Commit

Permalink
Fix float64 comparison in stats_helpers_test.go
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed May 16, 2017
1 parent 82600b7 commit 3c78bc7
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions cli/command/container/stats_helpers_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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) {
Expand All @@ -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)
})
}

0 comments on commit 3c78bc7

Please sign in to comment.