MCPcopy
hub / github.com/caddyserver/caddy / TestDirMode_UmaskInteraction

Function TestDirMode_UmaskInteraction

modules/logging/filewriter_test.go:563–589  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

561}
562
563func TestDirMode_UmaskInteraction(t *testing.T) {
564 _ = syscall.Umask(0o022) // typical umask; restore after
565 defer syscall.Umask(0)
566
567 base := t.TempDir()
568 dest := filepath.Join(base, "logs5")
569 fw := &FileWriter{
570 Filename: filepath.Join(dest, "app.log"),
571 DirMode: "0755",
572 Mode: 0o644,
573 Roll: func() *bool { f := false; return &f }(),
574 }
575 w, err := fw.OpenWriter()
576 if err != nil {
577 t.Fatal(err)
578 }
579 _ = w.Close()
580
581 st, err := os.Stat(dest)
582 if err != nil {
583 t.Fatal(err)
584 }
585 // 0755 &^ 0022 still 0755 for dirs; this just sanity-checks we didn't get stricter unexpectedly
586 if got := st.Mode().Perm(); got != 0o755 {
587 t.Fatalf("dir perm = %o, want 0755 (considering umask)", got)
588 }
589}
590
591func TestCaddyfile_DirMode_Inherit(t *testing.T) {
592 d := caddyfile.NewTestDispenser(`

Callers

nothing calls this directly

Calls 3

OpenWriterMethod · 0.95
StatMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected