25 lines
496 B
Go
25 lines
496 B
Go
package fileutil
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestWriteFileAtomicPreservesStricterMode(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "secret")
|
|
if err := os.WriteFile(path, []byte("old"), 0o400); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := WriteFileAtomic(path, []byte("new"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := info.Mode().Perm(); got != 0o400 {
|
|
t.Errorf("mode = %o, want 400", got)
|
|
}
|
|
}
|