File: ulimit_test.go

package info (click to toggle)
docker.io 27.5.1%2Bdfsg4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,384 kB
  • sloc: sh: 5,847; makefile: 1,146; ansic: 664; python: 162; asm: 133
file content (54 lines) | stat: -rw-r--r-- 1,391 bytes parent folder | download | duplicates (3)
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]")
}