forked from containers/buildah
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_test.go
83 lines (79 loc) · 2.1 KB
/
run_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package buildah
import (
"fmt"
"strings"
"testing"
"github.com/opencontainers/runtime-tools/generate"
)
func TestAddRlimits(t *testing.T) {
tt := []struct {
name string
ulimit []string
test func(error, *generate.Generator) error
}{
{
name: "empty ulimit",
ulimit: []string{},
test: func(e error, g *generate.Generator) error {
return e
},
},
{
name: "invalid ulimit argument",
ulimit: []string{"bla"},
test: func(e error, g *generate.Generator) error {
if e == nil {
return fmt.Errorf("expected to receive an error but got nil")
}
errMsg := "invalid ulimit argument"
if !strings.Contains(e.Error(), errMsg) {
return fmt.Errorf("expected error message to include %#v in %#v", errMsg, e.Error())
}
return nil
},
},
{
name: "invalid ulimit type",
ulimit: []string{"bla=hard"},
test: func(e error, g *generate.Generator) error {
if e == nil {
return fmt.Errorf("expected to receive an error but got nil")
}
errMsg := "invalid ulimit type"
if !strings.Contains(e.Error(), errMsg) {
return fmt.Errorf("expected error message to include %#v in %#v", errMsg, e.Error())
}
return nil
},
},
{
name: "valid ulimit",
ulimit: []string{"fsize=1024:4096"},
test: func(e error, g *generate.Generator) error {
if e != nil {
return e
}
rlimits := g.Config.Process.Rlimits
for _, rlimit := range rlimits {
if rlimit.Type == "RLIMIT_FSIZE" {
if rlimit.Hard != 4096 {
return fmt.Errorf("expected spec to have %#v hard limit set to %v but got %v", rlimit.Type, 4096, rlimit.Hard)
}
if rlimit.Soft != 1024 {
return fmt.Errorf("expected spec to have %#v hard limit set to %v but got %v", rlimit.Type, 1024, rlimit.Soft)
}
return nil
}
}
return fmt.Errorf("expected spec to have RLIMIT_FSIZE")
},
},
}
for _, tst := range tt {
g, _ := generate.New("linux")
err := addRlimits(tst.ulimit, &g, []string{})
if testErr := tst.test(err, &g); testErr != nil {
t.Errorf("test %#v failed: %v", tst.name, testErr)
}
}
}