Merge pull request #556 from Lomanic/winmemtest

[mem][windows] Fix TestVirtual_memory test
This commit is contained in:
shirou 2018-07-24 11:04:15 +09:00 committed by GitHub
commit d9d9688f3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -26,14 +26,24 @@ func TestVirtual_memory(t *testing.T) {
assert.True(t, v.Available > 0)
assert.True(t, v.Used > 0)
assert.Equal(t, v.Total, v.Used+v.Free+v.Buffers+v.Cached,
"Total should be computable (used + free + buffers + cached): %v", v)
total := v.Used + v.Free + v.Buffers + v.Cached
totalStr := "used + free + buffers + cached"
if runtime.GOOS == "windows" {
total = v.Used + v.Available
totalStr = "used + available"
}
assert.Equal(t, v.Total, total,
"Total should be computable (%v): %v", totalStr, v)
assert.True(t, v.Free > 0)
assert.True(t, runtime.GOOS == "windows" || v.Free > 0)
assert.True(t, v.Available > v.Free,
"Free should be a subset of Available: %v", v)
assert.InDelta(t, v.UsedPercent,
inDelta := assert.InDelta
if runtime.GOOS == "windows" {
inDelta = assert.InEpsilon
}
inDelta(t, v.UsedPercent,
100*float64(v.Used)/float64(v.Total), 0.1,
"UsedPercent should be how many percent of Total is Used: %v", v)
}