github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/internal/renameio/umask_test.go (about) 1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build !plan9 && !windows && !js 6 // +build !plan9,!windows,!js 7 8 package renameio 9 10 import ( 11 "os" 12 "path/filepath" 13 "syscall" 14 "testing" 15 ) 16 17 func TestWriteFileModeAppliesUmask(t *testing.T) { 18 dir := t.TempDir() 19 20 const mode = 0644 21 const umask = 0007 22 defer syscall.Umask(syscall.Umask(umask)) 23 24 file := filepath.Join(dir, "testWrite") 25 err := WriteFile(file, []byte("go-build"), mode) 26 if err != nil { 27 t.Fatalf("Failed to write file: %v", err) 28 } 29 30 fi, err := os.Stat(file) 31 if err != nil { 32 t.Fatalf("Stat %q (looking for mode %#o): %s", file, mode, err) 33 } 34 35 if fi.Mode()&os.ModePerm != 0640 { 36 t.Errorf("Stat %q: mode %#o want %#o", file, fi.Mode()&os.ModePerm, 0640) 37 } 38 }