forked from seccomp/libseccomp-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseccomp_ver_test.go
70 lines (67 loc) · 1.71 KB
/
seccomp_ver_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
package seccomp
import (
"testing"
)
func TestCheckVersion(t *testing.T) {
for _, tc := range []struct {
// input
op string
x, y, z uint
// expectations
isErr bool
}{
{op: "verNew", x: 100, y: 99, z: 7, isErr: true},
{op: "verMajor+1", x: verMajor + 1, isErr: true},
{op: "verMinor+1", x: verMajor, y: verMinor + 1, isErr: true},
{op: "verMicro+1", x: verMajor, y: verMinor, z: verMicro + 1, isErr: true},
// Current version is guaranteed to succeed.
{op: "verCur", x: verMajor, y: verMinor, z: verMicro},
// 2.2.0 is guaranteed to succeed.
{op: "verOld", x: 2, y: 2, z: 0},
} {
err := checkVersion(tc.op, tc.x, tc.y, tc.z)
t.Log(err)
if tc.isErr {
if err == nil {
t.Errorf("case %s: expected error, got nil", tc.op)
}
continue
}
if err != nil {
t.Errorf("case %s: expected no error, got %s", tc.op, err)
}
}
}
func TestCheckAPI(t *testing.T) {
curAPI, _ := getAPI()
for _, tc := range []struct {
// input
op string
level uint
x, y, z uint
// expectations
isErr bool
}{
{op: "apiHigh", level: 99, isErr: true},
{op: "api+1", level: curAPI + 1, isErr: true},
// Cases that should succeed.
{op: "apiCur", level: curAPI},
{op: "api0", level: 0},
{op: "apiCur_verCur", level: curAPI, x: verMajor, y: verMinor, z: verMicro},
// Adequate API level but version is too high.
{op: "verHigh", level: 0, x: 99, isErr: true},
// Other cases with version are checked by testCheckVersion.
} {
err := checkAPI(tc.op, tc.level, tc.x, tc.y, tc.z)
t.Log(err)
if tc.isErr {
if err == nil {
t.Errorf("case %s: expected error, got nil", tc.op)
}
continue
}
if err != nil {
t.Errorf("case %s: expected no error, got %s", tc.op, err)
}
}
}