github.com/avfs/avfs@v0.33.1-0.20240303173310-c6ba67c33eb7/vfs/osfs/osfs_test.go (about) 1 // 2 // Copyright 2020 The AVFS authors 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 //go:build !avfs_race 18 19 package osfs_test 20 21 import ( 22 "os" 23 "testing" 24 25 "github.com/avfs/avfs" 26 "github.com/avfs/avfs/test" 27 "github.com/avfs/avfs/vfs/osfs" 28 ) 29 30 var ( 31 // Tests that osfs.OsFS struct implements avfs.VFS interface. 32 _ avfs.VFS = &osfs.OsFS{} 33 34 // Tests that os.File struct implements avfs.File interface. 35 _ avfs.File = &os.File{} 36 ) 37 38 func TestOsFS(t *testing.T) { 39 vfs := osfs.New() 40 41 ts := test.NewSuiteFS(t, vfs, vfs) 42 ts.TestVFSAll(t) 43 } 44 45 func TestOsFSWithNoIdm(t *testing.T) { 46 vfs := osfs.NewWithNoIdm() 47 48 ts := test.NewSuiteFS(t, vfs, vfs) 49 ts.TestVFSAll(t) 50 } 51 52 func TestOsFSNilPtrFile(t *testing.T) { 53 f := (*os.File)(nil) 54 55 test.FileNilPtr(t, f) 56 } 57 58 func TestOsFSConfig(t *testing.T) { 59 vfs := osfs.New() 60 61 wantFeatures := avfs.FeatHardlink | avfs.FeatRealFS | avfs.FeatSymlink 62 if vfs.OSType() == avfs.OsLinux { 63 wantFeatures |= avfs.FeatIdentityMgr 64 } 65 66 if !vfs.User().IsAdmin() && vfs.OSType() != avfs.OsWindows { 67 wantFeatures |= avfs.FeatReadOnlyIdm 68 } 69 70 if vfs.Features() != wantFeatures { 71 t.Errorf("Features : want Features to be %s, got %s", wantFeatures, vfs.Features()) 72 } 73 74 name := vfs.Name() 75 if name != "" { 76 t.Errorf("Name : want name to be empty, got %v", name) 77 } 78 79 ostType := vfs.OSType() 80 if ostType != avfs.CurrentOSType() { 81 t.Errorf("OSType : want os type to be %v, got %v", avfs.CurrentOSType(), ostType) 82 } 83 } 84 85 func BenchmarkOsFSAll(b *testing.B) { 86 vfs := osfs.New() 87 88 ts := test.NewSuiteFS(b, vfs, vfs) 89 ts.BenchAll(b) 90 }