Skip to content

Commit a90cd2b

Browse files
author
Dongsu Park
committed
validation: print out correct diagnostics based on specError
Like other tests, `testNamespacePath` should also print out details about the failed tests, based on specError. Also make `waitForState(doCheckNamespacePath)` return a correct error coming from `checkNamespacePath`, not from `waitForState`. Signed-off-by: Dongsu Park <[email protected]>
1 parent 23c9a51 commit a90cd2b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

validation/linux_ns_path.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/mndrix/tap-go"
1212
rspec "github.com/opencontainers/runtime-spec/specs-go"
13+
"github.com/opencontainers/runtime-tools/specerror"
1314
"github.com/opencontainers/runtime-tools/validation/util"
1415
)
1516

@@ -52,6 +53,8 @@ func checkNamespacePath(unsharePid int, ns string) error {
5253
return fmt.Errorf("cannot read namespace link for the test process: %s\n%v\n%v", err, err2, string(out))
5354
}
5455

56+
var errNsPath error
57+
5558
unshareNsPath := ""
5659
unshareNsInode := ""
5760

@@ -75,11 +78,13 @@ func checkNamespacePath(unsharePid int, ns string) error {
7578
unshareNsPath = fmt.Sprintf("/proc/%d/ns/%s", unsharePid, ns+specialChildren)
7679
unshareNsInode, err = os.Readlink(unshareNsPath)
7780
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
7983
}
8084

8185
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
8388
}
8489

8590
return nil
@@ -88,7 +93,10 @@ func checkNamespacePath(unsharePid int, ns string) error {
8893
// Since it takes some time until unshare switched to the new namespace,
8994
// we should make a loop to check for the result up to 3 seconds.
9095
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
92100
}
93101

94102
g, err := util.GetDefaultGenerator()
@@ -173,8 +181,13 @@ func main() {
173181
err := testNamespacePath(t, c.name, c.unshareOpt)
174182
t.Ok(err == nil, fmt.Sprintf("set %s namespace by path", c.name))
175183
if err != nil {
184+
specErr := specerror.NewError(specerror.NSProcInPath, err, rspec.Version)
176185
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,
178191
}
179192
t.YAML(diagnostic)
180193
}

0 commit comments

Comments
 (0)