-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathulimit_test.go
54 lines (40 loc) · 1.36 KB
/
ulimit_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package opts
import (
"testing"
"github.com/docker/docker/api/types/container"
"gotest.tools/v3/assert"
)
func TestUlimitOpt(t *testing.T) {
ulimitMap := map[string]*container.Ulimit{
"nofile": {Name: "nofile", Hard: 1024, Soft: 512},
}
ulimitOpt := NewUlimitOpt(&ulimitMap)
expected := "[nofile=512:1024]"
assert.Equal(t, ulimitOpt.String(), expected)
// Valid ulimit append to opts
err := ulimitOpt.Set("core=1024:1024")
assert.NilError(t, err)
err = ulimitOpt.Set("nofile")
assert.ErrorContains(t, err, "invalid ulimit argument")
// Invalid ulimit type returns an error and do not append to opts
err = ulimitOpt.Set("notavalidtype=1024:1024")
assert.ErrorContains(t, err, "invalid ulimit type")
expected = "[core=1024:1024 nofile=512:1024]"
assert.Equal(t, ulimitOpt.String(), expected)
// And test GetList
ulimits := ulimitOpt.GetList()
assert.Equal(t, len(ulimits), 2)
}
func TestUlimitOptSorting(t *testing.T) {
ulimitOpt := NewUlimitOpt(&map[string]*container.Ulimit{
"nofile": {Name: "nofile", Hard: 1024, Soft: 512},
"core": {Name: "core", Hard: 1024, Soft: 1024},
})
expected := []*container.Ulimit{
{Name: "core", Hard: 1024, Soft: 1024},
{Name: "nofile", Hard: 1024, Soft: 512},
}
ulimits := ulimitOpt.GetList()
assert.DeepEqual(t, ulimits, expected)
assert.Equal(t, ulimitOpt.String(), "[core=1024:1024 nofile=512:1024]")
}