feat: add CPU and memory resource limits per app
All checks were successful
Check / check (pull_request) Successful in 3m24s
All checks were successful
Check / check (pull_request) Successful in 3m24s
- Add cpu_limit (REAL) and memory_limit (INTEGER) columns to apps table via migration 007 - Add CPULimit and MemoryLimit fields to App model with full CRUD support - Add resource limits fields to app edit form with human-friendly memory input (e.g. 256m, 1g, 512k) - Pass CPU and memory limits to Docker container creation via NanoCPUs and Memory host config fields - Extract Docker container creation helpers (buildEnvSlice, buildMounts, buildResources) for cleaner code - Add formatMemoryBytes template function for display - Add comprehensive tests for parsing, formatting, model persistence, and container options
This commit is contained in:
34
templates/templates_test.go
Normal file
34
templates/templates_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package templates //nolint:testpackage // tests unexported formatMemoryBytes
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFormatMemoryBytes(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
bytes int64
|
||||
expected string
|
||||
}{
|
||||
{"gigabytes", 1024 * 1024 * 1024, "1g"},
|
||||
{"two gigabytes", 2 * 1024 * 1024 * 1024, "2g"},
|
||||
{"megabytes", 256 * 1024 * 1024, "256m"},
|
||||
{"kilobytes", 512 * 1024, "512k"},
|
||||
{"plain bytes", 12345, "12345"},
|
||||
{"non-even megabytes", 256*1024*1024 + 1, "268435457"},
|
||||
{"zero", 0, "0"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got := formatMemoryBytes(tt.bytes)
|
||||
if got != tt.expected {
|
||||
t.Errorf("formatMemoryBytes(%d) = %q, want %q", tt.bytes, got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user