CBG-1760: Error upfront when the configured logFilePath is not writable
(t *testing.T)
| 51 | |
| 52 | // CBG-1760: Error upfront when the configured logFilePath is not writable |
| 53 | func 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 | } |
nothing calls this directly
no test coverage detected