MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestLogFilePathWritable

Function TestLogFilePathWritable

base/logging_config_test.go:53–94  ·  view source on GitHub ↗

CBG-1760: Error upfront when the configured logFilePath is not writable

(t *testing.T)

Source from the content-addressed store, hash-verified

51
52// CBG-1760: Error upfront when the configured logFilePath is not writable
53func TestLogFilePathWritable(t *testing.T) {
54 if runtime.GOOS == "windows" {
55 // Cannot make folder inaccessible to writes or make read-only: https://github.com/golang/go/issues/35042
56 t.Skip("Test not compatible with Windows")
57 }
58
59 testCases := []struct {
60 name string
61 logFilePathPerms os.FileMode
62 error bool
63 }{
64 {
65 name: "Unwritable",
66 logFilePathPerms: 0444, // Read-only perms
67 error: true,
68 },
69 {
70 name: "Writeable",
71 logFilePathPerms: 0777, // Full perms
72 error: false,
73 },
74 }
75 for _, test := range testCases {
76 // Create tempdir here to avoid slash operator in t.Name()
77 tmpPath := t.TempDir()
78 t.Logf("created tmpPath: %q", tmpPath)
79
80 t.Run(test.name, func(t *testing.T) {
81 logFilePath := filepath.Join(tmpPath, "logs")
82 err := os.Mkdir(logFilePath, test.logFilePathPerms)
83 require.NoError(t, err)
84
85 // The write-check is done inside validateLogFileOutput now.
86 err = validateLogFileOutput(filepath.Join(logFilePath, test.name+".log"))
87 if test.error {
88 assert.Error(t, err)
89 return
90 }
91 assert.NoError(t, err)
92 })
93 }
94}

Callers

nothing calls this directly

Calls 4

validateLogFileOutputFunction · 0.85
RunMethod · 0.65
LogfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected