
Commit 6a516acb2e
moved the MemInfo type and
ReadMemInfo() function into the pkg/sysinfo package. In an attempt to assist
consumers of these to migrate to the new location, an alias was added.
Unfortunately, the side effect of this alias is that pkg/system now depends
on pkg/sysinfo, which means that consumers of this (such as docker/cli) now
get all (indirect) dependencies of that package as dependency, which includes
many dependencies that should only be needed for the daemon / runtime;
- github.com/cilium/ebpf
- github.com/containerd/cgroups
- github.com/coreos/go-systemd/v22
- github.com/godbus/dbus/v5
- github.com/moby/sys/mountinfo
- github.com/opencontainers/runtime-spec
This patch moves the MemInfo related code to its own package. As the previous move
was not yet part of a release, we're not adding new aliases in pkg/sysinfo.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
43 lines
875 B
Go
43 lines
875 B
Go
//go:build linux || freebsd
|
|
// +build linux freebsd
|
|
|
|
package meminfo
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestMemInfo tests parseMemInfo with a static meminfo string
|
|
func TestMemInfo(t *testing.T) {
|
|
const input = `
|
|
MemTotal: 1 kB
|
|
MemFree: 2 kB
|
|
MemAvailable: 3 kB
|
|
SwapTotal: 4 kB
|
|
SwapFree: 5 kB
|
|
Malformed1:
|
|
Malformed2: 1
|
|
Malformed3: 2 MB
|
|
Malformed4: X kB
|
|
`
|
|
|
|
const KiB = 1024
|
|
|
|
meminfo, err := parseMemInfo(strings.NewReader(input))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if meminfo.MemTotal != 1*KiB {
|
|
t.Fatalf("Unexpected MemTotal: %d", meminfo.MemTotal)
|
|
}
|
|
if meminfo.MemFree != 3*KiB {
|
|
t.Fatalf("Unexpected MemFree: %d", meminfo.MemFree)
|
|
}
|
|
if meminfo.SwapTotal != 4*KiB {
|
|
t.Fatalf("Unexpected SwapTotal: %d", meminfo.SwapTotal)
|
|
}
|
|
if meminfo.SwapFree != 5*KiB {
|
|
t.Fatalf("Unexpected SwapFree: %d", meminfo.SwapFree)
|
|
}
|
|
}
|