fix(panel): show whole GiB for large switcher memory
- MachineSpecs keeps raw MiB up to 9600, then switches to a rounded whole GiB (e.g. 10000 -> "2c 10g") - cover the boundary and rounding in the group tests Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
This commit is contained in:
1 parent
8a73d1bd0f
commit
3df47aece0
2 files changed
+13
-3
No files matched your search
@@ -2,6 +2,7 @@ package mgr
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -21,11 +22,16 @@ func UserGroupLabel(name string) string {
|
||||
}
|
||||
|
||||
// MachineSpecs renders a compact quota tag for the container switcher:
|
||||
// "<cpu>c <mem>m <disk>g", e.g. "2c 2048m 15g". CPU reuses FormatCPU (tenths
|
||||
// of a core, so 0.5 stays fractional); memory is the raw MiB value; disk is
|
||||
// "<cpu>c <mem> <disk>g", e.g. "2c 2048m 15g". CPU reuses FormatCPU (tenths of
|
||||
// a core, so 0.5 stays fractional); memory is the raw MiB value, switching to
|
||||
// a rounded whole GiB once it exceeds 9600 MiB (so "2c 10g 15g"); disk is
|
||||
// already GiB.
|
||||
func MachineSpecs(cpuTenths, memMB, diskGB int) string {
|
||||
return FormatCPU(cpuTenths) + "c " + strconv.Itoa(memMB) + "m " + strconv.Itoa(diskGB) + "g"
|
||||
mem := strconv.Itoa(memMB) + "m"
|
||||
if memMB > 9600 {
|
||||
mem = strconv.Itoa(int(math.Round(float64(memMB)/1024))) + "g"
|
||||
}
|
||||
return FormatCPU(cpuTenths) + "c " + mem + " " + strconv.Itoa(diskGB) + "g"
|
||||
}
|
||||
|
||||
type UserGroup struct {
|
||||
|
||||
@@ -51,6 +51,10 @@ func TestMachineSpecs(t *testing.T) {
|
||||
{40, 8192, 40, "4c 8192m 40g"},
|
||||
{5, 512, 10, "0.5c 512m 10g"},
|
||||
{20, 1536, 20, "2c 1536m 20g"},
|
||||
{20, 9600, 20, "2c 9600m 20g"}, // boundary stays MiB
|
||||
{20, 10000, 20, "2c 10g 20g"}, // 9.77 -> 10
|
||||
{20, 10240, 20, "2c 10g 20g"}, // exact GiB
|
||||
{20, 11264, 20, "2c 11g 20g"}, // 11 GiB
|
||||
} {
|
||||
if got := MachineSpecs(test.cpu, test.mem, test.disk); got != test.want {
|
||||
t.Errorf("MachineSpecs(%d, %d, %d) = %q, want %q", test.cpu, test.mem, test.disk, got, test.want)
|
||||
|
||||
Reference in new issue
Block a user