@@ -10,6 +10,7 @@ import (
10
10
11
11
"github.com/mndrix/tap-go"
12
12
rspec "github.com/opencontainers/runtime-spec/specs-go"
13
+ "github.com/opencontainers/runtime-tools/specerror"
13
14
"github.com/opencontainers/runtime-tools/validation/util"
14
15
)
15
16
@@ -52,6 +53,8 @@ func checkNamespacePath(unsharePid int, ns string) error {
52
53
return fmt .Errorf ("cannot read namespace link for the test process: %s\n %v\n %v" , err , err2 , string (out ))
53
54
}
54
55
56
+ var errNsPath error
57
+
55
58
unshareNsPath := ""
56
59
unshareNsInode := ""
57
60
@@ -75,11 +78,13 @@ func checkNamespacePath(unsharePid int, ns string) error {
75
78
unshareNsPath = fmt .Sprintf ("/proc/%d/ns/%s" , unsharePid , ns + specialChildren )
76
79
unshareNsInode , err = os .Readlink (unshareNsPath )
77
80
if err != nil {
78
- return fmt .Errorf ("cannot read namespace link for the unshare process: %s" , err )
81
+ errNsPath = fmt .Errorf ("cannot read namespace link for the unshare process: %s" , err )
82
+ return errNsPath
79
83
}
80
84
81
85
if testNsInode == unshareNsInode {
82
- return fmt .Errorf ("expected: %q, found: %q" , testNsInode , unshareNsInode )
86
+ errNsPath = fmt .Errorf ("expected: %q, found: %q" , testNsInode , unshareNsInode )
87
+ return errNsPath
83
88
}
84
89
85
90
return nil
@@ -88,7 +93,10 @@ func checkNamespacePath(unsharePid int, ns string) error {
88
93
// Since it takes some time until unshare switched to the new namespace,
89
94
// we should make a loop to check for the result up to 3 seconds.
90
95
if err := waitForState (doCheckNamespacePath ); err != nil {
91
- return err
96
+ // we should return errNsPath instead of err, because errNsPath is what
97
+ // returned from the actual test function doCheckNamespacePath(), not
98
+ // waitForState().
99
+ return errNsPath
92
100
}
93
101
94
102
g , err := util .GetDefaultGenerator ()
@@ -173,8 +181,13 @@ func main() {
173
181
err := testNamespacePath (t , c .name , c .unshareOpt )
174
182
t .Ok (err == nil , fmt .Sprintf ("set %s namespace by path" , c .name ))
175
183
if err != nil {
184
+ specErr := specerror .NewError (specerror .NSProcInPath , err , rspec .Version )
176
185
diagnostic := map [string ]string {
177
- "error" : err .Error (),
186
+ "actual" : fmt .Sprintf ("err == %v" , err ),
187
+ "expected" : "err == nil" ,
188
+ "namespace type" : c .name ,
189
+ "level" : specErr .(* specerror.Error ).Err .Level .String (),
190
+ "reference" : specErr .(* specerror.Error ).Err .Reference ,
178
191
}
179
192
t .YAML (diagnostic )
180
193
}
0 commit comments