2017-04-27 14:17:47 -04:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2017-05-13 19:23:15 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-04-27 14:17:47 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCalculateMemUsageUnixNoCache(t *testing.T) {
|
|
|
|
// Given
|
|
|
|
stats := types.MemoryStats{Usage: 500, Stats: map[string]uint64{"cache": 400}}
|
|
|
|
|
|
|
|
// When
|
|
|
|
result := calculateMemUsageUnixNoCache(stats)
|
|
|
|
|
|
|
|
// Then
|
2017-05-13 19:23:15 -04:00
|
|
|
assert.InDelta(t, 100.0, result, 1e-6)
|
2017-04-27 14:17:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCalculateMemPercentUnixNoCache(t *testing.T) {
|
|
|
|
// Given
|
|
|
|
someLimit := float64(100.0)
|
|
|
|
noLimit := float64(0.0)
|
|
|
|
used := float64(70.0)
|
|
|
|
|
|
|
|
// When and Then
|
|
|
|
t.Run("Limit is set", func(t *testing.T) {
|
|
|
|
result := calculateMemPercentUnixNoCache(someLimit, used)
|
2017-05-13 19:23:15 -04:00
|
|
|
assert.InDelta(t, 70.0, result, 1e-6)
|
2017-04-27 14:17:47 -04:00
|
|
|
})
|
|
|
|
t.Run("No limit, no cgroup data", func(t *testing.T) {
|
|
|
|
result := calculateMemPercentUnixNoCache(noLimit, used)
|
2017-05-13 19:23:15 -04:00
|
|
|
assert.InDelta(t, 0.0, result, 1e-6)
|
2017-04-27 14:17:47 -04:00
|
|
|
})
|
|
|
|
}
|