forked from kata-containers/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespace_test.go
54 lines (44 loc) · 1.14 KB
/
namespace_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/sys/unix"
)
func TestSetupPersistentNs(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip("Test disabled as it requires root privileges")
}
ipcDirPath, err := ioutil.TempDir("", "ipc")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(ipcDirPath)
persistentNsDir = ipcDirPath
ns, err := setupPersistentNs(nsTypeIPC)
assert.Nil(t, err, "setupPersistentNs failed for IPC namespace: %v", err)
assert.NotNil(t, ns.path, "Path empty for persistent IPC namespace")
err = unix.Unmount(ns.path, unix.MNT_DETACH)
if err != nil {
t.Fatal(err)
}
utsDirPath, err := ioutil.TempDir("", "uts")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(utsDirPath)
persistentNsDir = utsDirPath
ns, err = setupPersistentNs(nsTypeUTS)
assert.Nil(t, err, "setupPersistentNs failed for UTS namespace: %v", err)
assert.NotNil(t, ns.path, "Path empty for persistent UTS namespace")
err = unix.Unmount(ns.path, unix.MNT_DETACH)
if err != nil {
t.Fatal(err)
}
}