github.com/google/osv-scalibr@v0.4.1/testing/fakefs/symlink_fs.go (about) 1 // Copyright 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package fakefs 16 17 import ( 18 "errors" 19 20 scalibrfs "github.com/google/osv-scalibr/fs" 21 ) 22 23 // MockEvalSymlinksFS is a mock implementation of image.EvalSymlinksFS for testing. 24 type MockEvalSymlinksFS struct { 25 scalibrfs.FS 26 27 Symlinks map[string]string 28 } 29 30 // NewMockEvalSymlinksFS creates a new MockEvalSymlinksFS. 31 func NewMockEvalSymlinksFS(fs scalibrfs.FS, symlinks map[string]string) *MockEvalSymlinksFS { 32 return &MockEvalSymlinksFS{ 33 FS: fs, 34 Symlinks: symlinks, 35 } 36 } 37 38 // EvalSymlink mocks the evaluation of symlinks. 39 func (fs *MockEvalSymlinksFS) EvalSymlink(name string) (string, error) { 40 if dest, ok := fs.Symlinks[name]; ok { 41 return dest, nil 42 } 43 return "", errors.New("not a symlink") 44 } 45 46 // The following should be true, but can't be uncommented because it would cause an import cycle 47 // (image_test.go is in the package image, rather than image_test because it uses the private chainLayer field.) 48 // var _ image.EvalSymlinksFS = &MockEvalSymlinksFS{}