github.com/avfs/avfs@v0.33.1-0.20240303173310-c6ba67c33eb7/umask_test.go (about) 1 // 2 // Copyright 2023 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 package avfs_test 18 19 import ( 20 "io/fs" 21 "testing" 22 23 "github.com/avfs/avfs" 24 ) 25 26 // TestUMaskOS tests Umask functions for the current OS. 27 func TestUMaskOS(t *testing.T) { 28 const ( 29 linuxUMask = fs.FileMode(0o22) 30 windowsUMask = fs.FileMode(0o111) 31 testUMask = fs.FileMode(0o77) 32 ) 33 34 saveUMask := avfs.UMask() 35 defer func() { _ = avfs.SetUMask(saveUMask) }() 36 37 defaultUMask := linuxUMask 38 if avfs.CurrentOSType() == avfs.OsWindows { 39 defaultUMask = windowsUMask 40 } 41 42 wantedUMask := defaultUMask 43 44 umask := avfs.UMask() 45 if umask != wantedUMask { 46 t.Errorf("UMask : want OS umask %o, got %o", wantedUMask, umask) 47 } 48 49 _ = avfs.SetUMask(testUMask) 50 51 umask = avfs.UMask() 52 if umask != testUMask { 53 t.Errorf("UMask : want test umask %o, got %o", testUMask, umask) 54 } 55 56 _ = avfs.SetUMask(defaultUMask) 57 58 umask = avfs.UMask() 59 if umask != defaultUMask { 60 t.Errorf("UMask : want OS umask %o, got %o", defaultUMask, umask) 61 } 62 }