File: ulimit_test.go

package info (click to toggle)
docker.io 20.10.24%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 60,824 kB
  • sloc: sh: 5,621; makefile: 593; ansic: 179; python: 162; asm: 7
file content (54 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download | duplicates (7)
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/go-units"
	"gotest.tools/v3/assert"
)

func TestUlimitOpt(t *testing.T) {
	ulimitMap := map[string]*units.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]*units.Ulimit{
		"nofile": {Name: "nofile", Hard: 1024, Soft: 512},
		"core":   {Name: "core", Hard: 1024, Soft: 1024},
	})

	expected := []*units.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]")
}