Skip to content

Commit a04e3ac

Browse files
committed
Write failing test case for create-symlinks hook
Signed-off-by: Christopher Desiniotis <cdesiniotis@nvidia.com>
1 parent 92779e7 commit a04e3ac

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

cmd/nvidia-cdi-hook/create-symlinks/create-symlinks_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,31 @@ func TestCreateLinkAlreadyExistsDifferentTarget(t *testing.T) {
108108
require.Equal(t, "different-target", target)
109109
}
110110

111+
func TestCreateLinkOutOfBounds(t *testing.T) {
112+
tmpDir := t.TempDir()
113+
hostRoot := filepath.Join(tmpDir, "/host-root/")
114+
containerRoot := filepath.Join(tmpDir, "/container-root")
115+
116+
require.NoError(t, makeFs(hostRoot))
117+
require.NoError(t,
118+
makeFs(containerRoot,
119+
dirOrLink{path: "/lib"},
120+
dirOrLink{path: "/lib/foo", target: hostRoot},
121+
),
122+
)
123+
124+
path, err := symlinks.Resolve(filepath.Join(containerRoot, "/lib/foo"))
125+
require.NoError(t, err)
126+
require.Equal(t, hostRoot, path)
127+
128+
// nvidia-cdi-hook create-symlinks --link ../libfoo.so.1::/lib/foo/libfoo.so
129+
_ = getTestCommand().createLink(containerRoot, "../libfoo.so.1", "/lib/foo/libfoo.so")
130+
// TODO: We need to enabled this check once we have updated the implementation.
131+
// require.Error(t, err)
132+
_, err = os.Lstat(filepath.Join(hostRoot, "libfoo.so"))
133+
require.ErrorIs(t, err, os.ErrNotExist)
134+
}
135+
111136
type dirOrLink struct {
112137
path string
113138
target string

0 commit comments

Comments
 (0)