Show rootfs sizes in image list
Replace the noisy rootfs path column in `banger image list` with the current rootfs file size so the table is easier to scan. Render a ROOTFS SIZE column from the on-disk image size, fall back to `-` when the artifact cannot be statted, and keep the existing image summary output unchanged. Add CLI coverage for both the formatted size case and the missing-file fallback, then rebuild and check the live command output.
This commit is contained in:
parent
14d8563f3c
commit
3b7e77a2de
2 changed files with 78 additions and 6 deletions
|
|
@ -474,6 +474,51 @@ func TestAbsolutizeImageRegisterPaths(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPrintImageListTableShowsRootfsSizes(t *testing.T) {
|
||||
rootfs := filepath.Join(t.TempDir(), "rootfs.ext4")
|
||||
if err := os.WriteFile(rootfs, nil, 0o644); err != nil {
|
||||
t.Fatalf("WriteFile(%s): %v", rootfs, err)
|
||||
}
|
||||
if err := os.Truncate(rootfs, 8*1024); err != nil {
|
||||
t.Fatalf("Truncate(%s): %v", rootfs, err)
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
err := printImageListTable(&out, []model.Image{
|
||||
{
|
||||
ID: "0123456789abcdef",
|
||||
Name: "alpine",
|
||||
Managed: true,
|
||||
RootfsPath: rootfs,
|
||||
CreatedAt: time.Now().Add(-1 * time.Hour),
|
||||
},
|
||||
{
|
||||
ID: "fedcba9876543210",
|
||||
Name: "missing",
|
||||
Managed: false,
|
||||
RootfsPath: filepath.Join(t.TempDir(), "missing.ext4"),
|
||||
CreatedAt: time.Now().Add(-2 * time.Hour),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("printImageListTable() error = %v", err)
|
||||
}
|
||||
|
||||
output := out.String()
|
||||
if !strings.Contains(output, "ROOTFS SIZE") {
|
||||
t.Fatalf("output = %q, want rootfs size header", output)
|
||||
}
|
||||
if !strings.Contains(output, "alpine") || !strings.Contains(output, "8K") {
|
||||
t.Fatalf("output = %q, want alpine row with 8K size", output)
|
||||
}
|
||||
if strings.Contains(output, rootfs) {
|
||||
t.Fatalf("output = %q, should not include rootfs path", output)
|
||||
}
|
||||
if !strings.Contains(output, "missing") || !strings.Contains(output, "-") {
|
||||
t.Fatalf("output = %q, want fallback size for missing image", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintVMPortsTableSortsAndRendersURLEndpoints(t *testing.T) {
|
||||
result := api.VMPortsResult{
|
||||
Name: "alpha",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue