Debian Codegraph @

seccomp_ver_test.go

raw symbols SCIP
1 package seccomp
2
3 import (
4 "testing"
5 )
6
7 func TestCheckVersion(t *testing.T) {
8 for _, tc := range []struct {
9 // input
10 op string
11 x, y, z uint
12 // expectations
13 isErr bool
14 }{
15 {op: "verNew", x: 100, y: 99, z: 7, isErr: true},
16 {op: "verMajor+1", x: verMajor + 1, isErr: true},
17 {op: "verMinor+1", x: verMajor, y: verMinor + 1, isErr: true},
18 {op: "verMicro+1", x: verMajor, y: verMinor, z: verMicro + 1, isErr: true},
19 // Current version is guaranteed to succeed.
20 {op: "verCur", x: verMajor, y: verMinor, z: verMicro},
21 // 2.2.0 is guaranteed to succeed.
22 {op: "verOld", x: 2, y: 2, z: 0},
23 } {
24 err := checkVersion(tc.op, tc.x, tc.y, tc.z)
25 t.Log(err)
26 if tc.isErr {
27 if err == nil {
28 t.Errorf("case %s: expected error, got nil", tc.op)
29 }
30 continue
31 }
32 if err != nil {
33 t.Errorf("case %s: expected no error, got %s", tc.op, err)
34 }
35 }
36 }
37
38 func TestCheckAPI(t *testing.T) {
39 curAPI, _ := getAPI()
40 for _, tc := range []struct {
41 // input
42 op string
43 level uint
44 x, y, z uint
45 // expectations
46 isErr bool
47 }{
48 {op: "apiHigh", level: 99, isErr: true},
49 {op: "api+1", level: curAPI + 1, isErr: true},
50 // Cases that should succeed.
51 {op: "apiCur", level: curAPI},
52 {op: "api0", level: 0},
53 {op: "apiCur_verCur", level: curAPI, x: verMajor, y: verMinor, z: verMicro},
54 // Adequate API level but version is too high.
55 {op: "verHigh", level: 0, x: 99, isErr: true},
56 // Other cases with version are checked by testCheckVersion.
57 } {
58 err := checkAPI(tc.op, tc.level, tc.x, tc.y, tc.z)
59 t.Log(err)
60 if tc.isErr {
61 if err == nil {
62 t.Errorf("case %s: expected error, got nil", tc.op)
63 }
64 continue
65 }
66 if err != nil {
67 t.Errorf("case %s: expected no error, got %s", tc.op, err)
68 }
69 }
70 }