mirror of
https://github.com/lima-vm/lima.git
synced 2026-10-28 11:44:35 +08:00
Merge pull request #5596 from nightcityblade/fix/issue-5591
limactl menu: display memory with binary units
This commit is contained in:
2 files changed
+23
-2
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/go-units"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -141,8 +142,7 @@ func fmtInst(in *limatype.Instance) string {
|
||||
name = name[:13] + "..."
|
||||
}
|
||||
|
||||
mem := float64(in.Memory) / 1e9
|
||||
cpusMem := fmt.Sprintf("%dCPU/%.1fGB", in.CPUs, mem)
|
||||
cpusMem := fmt.Sprintf("%dCPU/%s", in.CPUs, units.BytesSize(float64(in.Memory)))
|
||||
|
||||
sshAddr := fmt.Sprintf("%s:%d", in.SSHAddress, in.SSHLocalPort)
|
||||
if in.SSHAddress == "" || in.SSHLocalPort == 0 {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// SPDX-FileCopyrightText: Copyright The Lima Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
"github.com/lima-vm/lima/v2/pkg/limatype"
|
||||
)
|
||||
|
||||
func TestFmtInstUsesBinaryMemoryUnits(t *testing.T) {
|
||||
inst := &limatype.Instance{
|
||||
Name: "default", Status: limatype.StatusRunning, CPUs: 4, Memory: 4 << 30,
|
||||
}
|
||||
formatted := fmtInst(inst)
|
||||
assert.Assert(t, strings.Contains(formatted, "4CPU/4GiB"), formatted)
|
||||
}
|
||||
Reference in new issue
Block a user