2020-06-16 16:09:48 -05:00
|
|
|
/*
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2020-11-17 15:18:59 -06:00
|
|
|
"os"
|
|
|
|
|
2020-11-16 19:24:06 -06:00
|
|
|
kustfs "sigs.k8s.io/kustomize/api/filesys"
|
2020-08-12 00:26:09 -05:00
|
|
|
|
2020-11-16 19:24:06 -06:00
|
|
|
"opendev.org/airship/airshipctl/pkg/fs"
|
2020-06-16 16:09:48 -05:00
|
|
|
)
|
|
|
|
|
2020-11-16 19:24:06 -06:00
|
|
|
var _ fs.FileSystem = MockFileSystem{}
|
2020-08-12 00:26:09 -05:00
|
|
|
|
2020-06-16 16:09:48 -05:00
|
|
|
// MockFileSystem implements Filesystem
|
|
|
|
type MockFileSystem struct {
|
|
|
|
MockRemoveAll func() error
|
|
|
|
MockTempDir func() (string, error)
|
2020-08-12 00:26:09 -05:00
|
|
|
// allow to check content of the incoming parameters, root and patter for temp file
|
2020-11-16 19:24:06 -06:00
|
|
|
MockTempFile func(string, string) (fs.File, error)
|
2020-11-17 15:18:59 -06:00
|
|
|
MockChmod func(string, os.FileMode) error
|
|
|
|
MockDir func(string) string
|
2020-11-16 19:24:06 -06:00
|
|
|
kustfs.FileSystem
|
2020-06-16 16:09:48 -05:00
|
|
|
}
|
|
|
|
|
2020-09-21 02:49:33 -05:00
|
|
|
// RemoveAll Filesystem interface implementation
|
2020-06-16 16:09:48 -05:00
|
|
|
func (fsys MockFileSystem) RemoveAll(string) error { return fsys.MockRemoveAll() }
|
|
|
|
|
2020-09-21 02:49:33 -05:00
|
|
|
// TempFile Filesystem interface implementation
|
2020-11-16 19:24:06 -06:00
|
|
|
func (fsys MockFileSystem) TempFile(root, pattern string) (fs.File, error) {
|
2020-08-12 00:26:09 -05:00
|
|
|
return fsys.MockTempFile(root, pattern)
|
2020-06-16 16:09:48 -05:00
|
|
|
}
|
|
|
|
|
2020-09-21 02:49:33 -05:00
|
|
|
// TempDir Filesystem interface implementation
|
2020-06-16 16:09:48 -05:00
|
|
|
func (fsys MockFileSystem) TempDir(string, string) (string, error) {
|
|
|
|
return fsys.MockTempDir()
|
|
|
|
}
|
|
|
|
|
2020-11-17 15:18:59 -06:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2020-06-16 16:09:48 -05:00
|
|
|
// TestFile implements file
|
|
|
|
type TestFile struct {
|
2020-11-16 19:24:06 -06:00
|
|
|
fs.File
|
2020-06-16 16:09:48 -05:00
|
|
|
MockName func() string
|
2021-03-30 14:21:11 -04:00
|
|
|
MockWrite func([]byte) (int, error)
|
2020-06-16 16:09:48 -05:00
|
|
|
MockClose func() error
|
|
|
|
}
|
|
|
|
|
2020-09-21 02:49:33 -05:00
|
|
|
// Name File interface implementation
|
2020-06-16 16:09:48 -05:00
|
|
|
func (f TestFile) Name() string { return f.MockName() }
|
|
|
|
|
2020-09-21 02:49:33 -05:00
|
|
|
// Write File interface implementation
|
2021-03-30 14:21:11 -04:00
|
|
|
func (f TestFile) Write(b []byte) (int, error) { return f.MockWrite(b) }
|
2020-06-16 16:09:48 -05:00
|
|
|
|
2020-09-21 02:49:33 -05:00
|
|
|
// Close File interface implementation
|
2020-06-16 16:09:48 -05:00
|
|
|
func (f TestFile) Close() error { return f.MockClose() }
|