Extend document filesystem with chmod and dir methods
These methods will be used instead of calling their direct analogs in the code in order to have more consistency. Change-Id: Ie2eaf03b1fbd049ed5788f1a769a332ef863494b Signed-off-by: Ruslan Aliev <raliev@mirantis.com> Relates-To: #415
This commit is contained in:
parent
e187740af8
commit
05b5ca599b
@ -16,6 +16,8 @@ package fs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
kustfs "sigs.k8s.io/kustomize/api/filesys"
|
kustfs "sigs.k8s.io/kustomize/api/filesys"
|
||||||
)
|
)
|
||||||
@ -31,6 +33,8 @@ type FileSystem interface {
|
|||||||
kustfs.FileSystem
|
kustfs.FileSystem
|
||||||
TempFile(string, string) (File, error)
|
TempFile(string, string) (File, error)
|
||||||
TempDir(string, string) (string, error)
|
TempDir(string, string) (string, error)
|
||||||
|
Chmod(string, os.FileMode) error
|
||||||
|
Dir(string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs is adaptor to TempFile
|
// Fs is adaptor to TempFile
|
||||||
@ -52,3 +56,13 @@ func (dfs Fs) TempFile(tmpDir string, prefix string) (File, error) {
|
|||||||
func (dfs Fs) TempDir(rootDir string, prefix string) (string, error) {
|
func (dfs Fs) TempDir(rootDir string, prefix string) (string, error) {
|
||||||
return ioutil.TempDir(rootDir, prefix)
|
return ioutil.TempDir(rootDir, prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Chmod applies desired permissions on file
|
||||||
|
func (dfs Fs) Chmod(path string, mode os.FileMode) error {
|
||||||
|
return os.Chmod(path, mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dir returns all but the last element of path, typically the path's directory
|
||||||
|
func (dfs Fs) Dir(path string) string {
|
||||||
|
return filepath.Dir(path)
|
||||||
|
}
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
kustfs "sigs.k8s.io/kustomize/api/filesys"
|
kustfs "sigs.k8s.io/kustomize/api/filesys"
|
||||||
|
|
||||||
"opendev.org/airship/airshipctl/pkg/fs"
|
"opendev.org/airship/airshipctl/pkg/fs"
|
||||||
@ -28,6 +30,8 @@ type MockFileSystem struct {
|
|||||||
MockTempDir func() (string, error)
|
MockTempDir func() (string, error)
|
||||||
// allow to check content of the incoming parameters, root and patter for temp file
|
// allow to check content of the incoming parameters, root and patter for temp file
|
||||||
MockTempFile func(string, string) (fs.File, error)
|
MockTempFile func(string, string) (fs.File, error)
|
||||||
|
MockChmod func(string, os.FileMode) error
|
||||||
|
MockDir func(string) string
|
||||||
kustfs.FileSystem
|
kustfs.FileSystem
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +48,16 @@ func (fsys MockFileSystem) TempDir(string, string) (string, error) {
|
|||||||
return fsys.MockTempDir()
|
return fsys.MockTempDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Chmod Filesystem interface implementation
|
||||||
|
func (fsys MockFileSystem) Chmod(path string, mode os.FileMode) error {
|
||||||
|
return fsys.MockChmod(path, mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dir Filesystem interface implementation
|
||||||
|
func (fsys MockFileSystem) Dir(path string) string {
|
||||||
|
return fsys.MockDir(path)
|
||||||
|
}
|
||||||
|
|
||||||
// TestFile implements file
|
// TestFile implements file
|
||||||
type TestFile struct {
|
type TestFile struct {
|
||||||
fs.File
|
fs.File
|
||||||
|
Loading…
Reference in New Issue
Block a user