gitee.com/leisunstar/runtime@v0.0.0-20200521203717-5cef3e7b53f9/virtcontainers/syscall_test.go (about) 1 // Copyright 2015 The rkt Authors 2 // Copyright (c) 2016 Intel Corporation 3 // 4 // SPDX-License-Identifier: Apache-2.0 5 // 6 7 package virtcontainers 8 9 import ( 10 "os" 11 "path/filepath" 12 "testing" 13 14 "github.com/stretchr/testify/assert" 15 ) 16 17 func TestEnsureDestinationExistsNonExistingSource(t *testing.T) { 18 err := ensureDestinationExists("", "") 19 assert.Error(t, err) 20 } 21 22 func TestEnsureDestinationExistsWrongParentDir(t *testing.T) { 23 source := filepath.Join(testDir, "fooFile") 24 dest := filepath.Join(source, "fooDest") 25 os.Remove(source) 26 os.Remove(dest) 27 assert := assert.New(t) 28 29 file, err := os.OpenFile(source, os.O_CREATE, mountPerm) 30 assert.NoError(err) 31 defer file.Close() 32 33 err = ensureDestinationExists(source, dest) 34 assert.Error(err) 35 } 36 37 func TestEnsureDestinationExistsSuccessfulSrcDir(t *testing.T) { 38 source := filepath.Join(testDir, "fooDirSrc") 39 dest := filepath.Join(testDir, "fooDirDest") 40 os.Remove(source) 41 os.Remove(dest) 42 assert := assert.New(t) 43 44 err := os.MkdirAll(source, mountPerm) 45 assert.NoError(err) 46 defer os.Remove(source) 47 48 err = ensureDestinationExists(source, dest) 49 assert.NoError(err) 50 } 51 52 func TestEnsureDestinationExistsSuccessfulSrcFile(t *testing.T) { 53 source := filepath.Join(testDir, "fooFileSrc") 54 dest := filepath.Join(testDir, "fooFileDest") 55 os.Remove(source) 56 os.Remove(dest) 57 assert := assert.New(t) 58 59 file, err := os.OpenFile(source, os.O_CREATE, mountPerm) 60 assert.NoError(err) 61 defer file.Close() 62 63 err = ensureDestinationExists(source, dest) 64 assert.NoError(err) 65 }