mirror of
https://github.com/amir20/dozzle.git
synced 2026-06-23 04:10:12 +00:00
5e780eb767
Push container / Push branches and PRs (push) Has been cancelled
Deploy VitePress site to Pages / build (push) Has been cancelled
Test / Typecheck (push) Has been cancelled
Test / JavaScript Tests (push) Has been cancelled
Test / Go Tests (push) Has been cancelled
Test / Go Staticcheck (push) Has been cancelled
Test / Integration Tests (push) Has been cancelled
Deploy VitePress site to Pages / Deploy (push) Has been cancelled
Co-authored-by: codedoga <codedoga@users.noreply.github.com>
84 lines
1.4 KiB
Go
84 lines
1.4 KiB
Go
package docker
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/moby/moby/api/types/container"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_calculateMemUsageUnixNoCache(t *testing.T) {
|
|
type args struct {
|
|
mem container.MemoryStats
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want float64
|
|
}{
|
|
{
|
|
name: "with cgroup v1",
|
|
args: args{
|
|
mem: container.MemoryStats{
|
|
Usage: 100,
|
|
Stats: map[string]uint64{
|
|
"total_inactive_file": 1,
|
|
},
|
|
},
|
|
},
|
|
want: 99,
|
|
},
|
|
{
|
|
name: "with cgroup v2",
|
|
args: args{
|
|
mem: container.MemoryStats{
|
|
Usage: 100,
|
|
Stats: map[string]uint64{
|
|
"inactive_file": 2,
|
|
},
|
|
},
|
|
},
|
|
want: 98,
|
|
},
|
|
{
|
|
name: "without cgroup",
|
|
args: args{
|
|
mem: container.MemoryStats{
|
|
Usage: 100,
|
|
},
|
|
},
|
|
want: 100,
|
|
},
|
|
{
|
|
name: "cgroup v2 with zero Usage falls back to anon",
|
|
args: args{
|
|
mem: container.MemoryStats{
|
|
Usage: 0,
|
|
Stats: map[string]uint64{
|
|
"inactive_file": 0,
|
|
"anon": 50,
|
|
},
|
|
},
|
|
},
|
|
want: 50,
|
|
},
|
|
{
|
|
name: "cgroup v2 with zero Usage and no anon returns 0",
|
|
args: args{
|
|
mem: container.MemoryStats{
|
|
Usage: 0,
|
|
Stats: map[string]uint64{
|
|
"inactive_file": 0,
|
|
},
|
|
},
|
|
},
|
|
want: 0,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equalf(t, tt.want, calculateMemUsageUnixNoCache(tt.args.mem), "calculateMemUsageUnixNoCache(%v)", tt.args.mem)
|
|
})
|
|
}
|
|
}
|