Skip to content

Commit f4bf52a

Browse files
committed
fix(tests): address review comments on TestFindNS
Use a dummy path instead of a real proc path in the "namespace type missing from spec" case, merge the assert.False call and its message onto one line, and drop the unnecessary file creation in the "existing path" case since t.TempDir() already returns a real directory. Also fixes the gosec G306 warning on the removed WriteFile call. Signed-off-by: Anand-240 <anandprakashsrivastava68@gmail.com>
1 parent 2385fe8 commit f4bf52a

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

pkg/unikontainers/utils_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/opencontainers/runtime-spec/specs-go"
2626
"github.com/stretchr/testify/assert"
27-
"github.com/stretchr/testify/require"
2827
)
2928

3029
func TestWritePidFile(t *testing.T) {
@@ -252,13 +251,12 @@ func TestFindNS(t *testing.T) {
252251
t.Run("namespace type missing from spec", func(t *testing.T) {
253252
t.Parallel()
254253
namespaces := []specs.LinuxNamespace{
255-
{Type: specs.NetworkNamespace, Path: "/proc/1/ns/net"},
254+
{Type: specs.NetworkNamespace, Path: "/dummy/path"},
256255
}
257256
path, err := findNS(namespaces, specs.MountNamespace)
258257
assert.Empty(t, path)
259258
assert.Error(t, err)
260-
assert.False(t, errors.Is(err, ErrNotExistingNS),
261-
"a namespace type absent from the spec must not be reported as ErrNotExistingNS")
259+
assert.False(t, errors.Is(err, ErrNotExistingNS), "a namespace type absent from the spec must not be reported as ErrNotExistingNS")
262260
})
263261

264262
t.Run("namespace present without a path yet", func(t *testing.T) {
@@ -273,8 +271,7 @@ func TestFindNS(t *testing.T) {
273271

274272
t.Run("namespace present with an existing path", func(t *testing.T) {
275273
t.Parallel()
276-
nsPath := filepath.Join(t.TempDir(), "mnt")
277-
require.NoError(t, os.WriteFile(nsPath, []byte{}, 0644))
274+
nsPath := t.TempDir()
278275

279276
namespaces := []specs.LinuxNamespace{
280277
{Type: specs.MountNamespace, Path: nsPath},

0 commit comments

Comments
 (0)