2021-02-17 08:55:50 -05:00
|
|
|
package oci
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2020-12-03 10:20:30 -05:00
|
|
|
"github.com/opencontainers/runc/libcontainer/devices"
|
2021-02-17 08:55:50 -05:00
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDeviceMode(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
in os.FileMode
|
|
|
|
out os.FileMode
|
|
|
|
}{
|
|
|
|
{name: "regular permissions", in: 0777, out: 0777},
|
|
|
|
{name: "block device", in: 0777 | unix.S_IFBLK, out: 0777},
|
|
|
|
{name: "character device", in: 0777 | unix.S_IFCHR, out: 0777},
|
|
|
|
{name: "fifo device", in: 0777 | unix.S_IFIFO, out: 0777},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
tc := tc
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2020-12-03 10:20:30 -05:00
|
|
|
d := Device(&devices.Device{FileMode: tc.in})
|
2021-02-17 08:55:50 -05:00
|
|
|
assert.Equal(t, *d.FileMode, tc.out)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|