Monorepo for Tangled
tangled.org
1package microvm
2
3import (
4 "testing"
5)
6
7func TestSanitizeCgroupName(t *testing.T) {
8 cases := []struct {
9 in string
10 want string
11 }{
12 {"workflow-abc123", "workflow-abc123"},
13 {"a/b:c", "a-b-c"},
14 {"--lead--", "lead"},
15 {"a__b..c", "a-b-c"},
16 {"keep.dots_and-dashes", "keep.dots_and-dashes"},
17 {"", ""},
18 {"///", ""},
19 }
20 for _, tc := range cases {
21 if got := sanitizeCgroupName(tc.in); got != tc.want {
22 t.Errorf("sanitizeCgroupName(%q) = %q, want %q", tc.in, got, tc.want)
23 }
24 }
25}
26
27func TestCgroupResourcesSwapOnlyStillSetsMemory(t *testing.T) {
28 swap := int64(8)
29 r := cgroupResources(CgroupLimits{SwapMaxMiB: &swap})
30 if r.Memory == nil {
31 t.Fatal("a swap limit alone should still produce a memory controller config")
32 }
33 if r.Memory.Max != nil {
34 t.Errorf("memory max should be unset when only swap is limited, got %v", *r.Memory.Max)
35 }
36 if r.Memory.Swap == nil || *r.Memory.Swap != 8*1024*1024 {
37 t.Errorf("swap = %v, want %d bytes", r.Memory.Swap, 8*1024*1024)
38 }
39}