summaryrefslogtreecommitdiff
path: root/libpod/info_test.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2022-04-28 12:31:17 -0500
committerMatthew Heon <matthew.heon@pm.me>2022-05-03 13:52:17 -0400
commit8842e9b7abde1135b2b4a7b876aa8897a624b397 (patch)
tree9f0435f4e09c2bca399ffcbaae0806dc82e42192 /libpod/info_test.go
parent6422048212572356e632e53e7a06b8ef8f7ef46f (diff)
downloadpodman-8842e9b7abde1135b2b4a7b876aa8897a624b397.tar.gz
podman-8842e9b7abde1135b2b4a7b876aa8897a624b397.tar.bz2
podman-8842e9b7abde1135b2b4a7b876aa8897a624b397.zip
Additional stats for podman info
In support of podman machine and its counterpart desktop, we have added new stats to podman info. For storage, we have added GraphRootAllocated and GraphRootUsed in bytes. For CPUs, we have added user, system, and idle percents based on /proc/stat. Fixes: #13876 Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'libpod/info_test.go')
-rw-r--r--libpod/info_test.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/libpod/info_test.go b/libpod/info_test.go
new file mode 100644
index 000000000..909b573c0
--- /dev/null
+++ b/libpod/info_test.go
@@ -0,0 +1,59 @@
+package libpod
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/containers/podman/v4/libpod/define"
+ "github.com/stretchr/testify/assert"
+)
+
+func Test_statToPercent(t *testing.T) {
+ type args struct {
+ in0 []string
+ }
+ tests := []struct {
+ name string
+ args args
+ want *define.CPUUsage
+ wantErr assert.ErrorAssertionFunc
+ }{
+ {
+ name: "GoodParse",
+ args: args{in0: []string{"cpu", " ", "33628064", "27537", "9696996", "1314806705", "588142", "4775073", "2789228", "0", "598711", "0"}},
+ want: &define.CPUUsage{
+ UserPercent: 2.48,
+ SystemPercent: 0.71,
+ IdlePercent: 96.81,
+ },
+ wantErr: assert.NoError,
+ },
+ {
+ name: "BadUserValue",
+ args: args{in0: []string{"cpu", " ", "k", "27537", "9696996", "1314806705", "588142", "4775073", "2789228", "0", "598711", "0"}},
+ want: nil,
+ wantErr: assert.Error,
+ },
+ {
+ name: "BadSystemValue",
+ args: args{in0: []string{"cpu", " ", "33628064", "27537", "k", "1314806705", "588142", "4775073", "2789228", "0", "598711", "0"}},
+ want: nil,
+ wantErr: assert.Error,
+ },
+ {
+ name: "BadIdleValue",
+ args: args{in0: []string{"cpu", " ", "33628064", "27537", "9696996", "k", "588142", "4775073", "2789228", "0", "598711", "0"}},
+ want: nil,
+ wantErr: assert.Error,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, err := statToPercent(tt.args.in0)
+ if !tt.wantErr(t, err, fmt.Sprintf("statToPercent(%v)", tt.args.in0)) {
+ return
+ }
+ assert.Equalf(t, tt.want, got, "statToPercent(%v)", tt.args.in0)
+ })
+ }
+}