github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/persist/fs/mockfs.go (about) 1 // Copyright (c) 2020 Intel Corporation 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 6 package fs 7 8 import ( 9 "fmt" 10 "os" 11 "path/filepath" 12 13 persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api" 14 ) 15 16 type MockFS struct { 17 // inherit from FS. Overwrite if needed. 18 *FS 19 } 20 21 func MockStorageRootPath() string { 22 return filepath.Join(os.TempDir(), "vc", "mockfs") 23 } 24 25 func MockRunStoragePath() string { 26 return filepath.Join(MockStorageRootPath(), sandboxPathSuffix) 27 } 28 29 func MockRunVMStoragePath() string { 30 return filepath.Join(MockStorageRootPath(), vmPathSuffix) 31 } 32 33 func MockStorageDestroy() { 34 os.RemoveAll(MockStorageRootPath()) 35 } 36 37 func MockFSInit() (persistapi.PersistDriver, error) { 38 driver, err := Init() 39 if err != nil { 40 return nil, fmt.Errorf("Could not create Mock FS driver: %v", err) 41 } 42 43 fsDriver, ok := driver.(*FS) 44 if !ok { 45 return nil, fmt.Errorf("Could not create Mock FS driver") 46 } 47 48 fsDriver.storageRootPath = MockStorageRootPath() 49 fsDriver.driverName = "mockfs" 50 51 return &MockFS{fsDriver}, nil 52 }