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-13 23:23:15 +00:00
parent 82600b7021
commit 3c78bc775c
1 changed files with 6 additions and 12 deletions

View File

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