Debian Codegraph @

internal/renameio/umask_test.go

raw
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
7 package renameio
8
9 import (
10 "os"
11 "path/filepath"
12 "syscall"
13 "testing"
14 )
15
16 func TestWriteFileModeAppliesUmask(t *testing.T) {
17 dir := t.TempDir()
18
19 const mode = 0644
20 const umask = 0007
21 defer syscall.Umask(syscall.Umask(umask))
22
23 file := filepath.Join(dir, "testWrite")
24 err := WriteFile(file, []byte("go-build"), mode)
25 if err != nil {
26 t.Fatalf("Failed to write file: %v", err)
27 }
28
29 fi, err := os.Stat(file)
30 if err != nil {
31 t.Fatalf("Stat %q (looking for mode %#o): %s", file, mode, err)
32 }
33
34 if fi.Mode()&os.ModePerm != 0640 {
35 t.Errorf("Stat %q: mode %#o want %#o", file, fi.Mode()&os.ModePerm, 0640)
36 }
37 }