| 1 |
// Copyright The Notary Project Authors. |
| 2 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 |
// you may not use this file except in compliance with the License. |
| 4 |
// You may obtain a copy of the License at |
| 5 |
// |
| 6 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
// |
| 8 |
// Unless required by applicable law or agreed to in writing, software |
| 9 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 |
// See the License for the specific language governing permissions and |
| 12 |
// limitations under the License. |
| 13 |
|
| 14 |
package mockfs |
| 15 |
|
| 16 |
import ( |
| 17 |
"io/fs" |
| 18 |
"path/filepath" |
| 19 |
|
| 20 |
"github.com/notaryproject/notation-go/dir" |
| 21 |
) |
| 22 |
|
| 23 |
type sysFSMock struct { |
| 24 |
fs.FS |
| 25 |
root string |
| 26 |
} |
| 27 |
|
| 28 |
// SysPath returns the system path of the FS. |
| 29 |
func (s sysFSMock) SysPath(items ...string) (string, error) { |
| 30 |
pathItems := []string{s.root} |
| 31 |
pathItems = append(pathItems, items...) |
| 32 |
return filepath.Join(pathItems...), nil |
| 33 |
} |
| 34 |
|
| 35 |
// NewSysFSMock returns a SysFS mock of the given FS. |
| 36 |
func NewSysFSMock(fsys fs.FS) dir.SysFS { |
| 37 |
return sysFSMock{ |
| 38 |
FS: fsys, |
| 39 |
root: ""} |
| 40 |
} |
| 41 |
|
| 42 |
// NewSysFSWithRootMock returns a SysFS mock of the given fs and |
| 43 |
// a root directory |
| 44 |
func NewSysFSWithRootMock(fsys fs.FS, root string) dir.SysFS { |
| 45 |
return sysFSMock{ |
| 46 |
FS: fsys, |
| 47 |
root: root} |
| 48 |
} |