Fix float64 comparison in stats_helpers_test.go

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2017-05-16 02:13:00 +00:00
parent 82600b7021
commit 3c78bc775c
+6 -12
View File
@@ -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)
})
}