gitee.com/leisunstar/runtime@v0.0.0-20200521203717-5cef3e7b53f9/virtcontainers/utils/utils_linux_test.go (about) 1 // Copyright (c) 2018 Intel Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package utils 7 8 import ( 9 "errors" 10 "testing" 11 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestFindContextID(t *testing.T) { 16 assert := assert.New(t) 17 18 ioctlFunc = func(fd uintptr, request, arg1 uintptr) error { 19 return errors.New("ioctl") 20 } 21 22 orgVHostVSockDevicePath := VHostVSockDevicePath 23 orgMaxUInt := maxUInt 24 defer func() { 25 VHostVSockDevicePath = orgVHostVSockDevicePath 26 maxUInt = orgMaxUInt 27 }() 28 VHostVSockDevicePath = "/dev/null" 29 maxUInt = uint64(1000000) 30 31 f, cid, err := FindContextID() 32 assert.Nil(f) 33 assert.Zero(cid) 34 assert.Error(err) 35 } 36 37 func TestGetDevicePathAndFsTypeEmptyMount(t *testing.T) { 38 assert := assert.New(t) 39 _, _, err := GetDevicePathAndFsType("") 40 assert.Error(err) 41 } 42 43 func TestGetDevicePathAndFsTypeSuccessful(t *testing.T) { 44 assert := assert.New(t) 45 46 path, fstype, err := GetDevicePathAndFsType("/proc") 47 assert.NoError(err) 48 49 assert.Equal(path, "proc") 50 assert.Equal(fstype, "proc") 51 }