| 118 | } |
| 119 | |
| 120 | func (tp *temp) SaveToWriter(writer func(file io.Writer) error, key ...string) string { |
| 121 | tp.t.Helper() |
| 122 | |
| 123 | tp.Dir(key[:len(key)-1]...) |
| 124 | |
| 125 | pth := filepath.Join(append([]string{tp.tempDir}, key...)...) |
| 126 | silentT := assertive.WithSilentSuccess(tp.t) |
| 127 | |
| 128 | //nolint:gosec // it is fine |
| 129 | file, err := os.OpenFile(pth, os.O_CREATE|os.O_WRONLY, FilePermissionsDefault) |
| 130 | assertive.ErrorIsNil( |
| 131 | silentT, |
| 132 | err, |
| 133 | fmt.Sprintf("Opening file %q must succeed", pth), |
| 134 | ) |
| 135 | |
| 136 | defer func() { |
| 137 | err = file.Close() |
| 138 | assertive.ErrorIsNil( |
| 139 | silentT, |
| 140 | err, |
| 141 | fmt.Sprintf("Closing file %q must succeed", pth), |
| 142 | ) |
| 143 | }() |
| 144 | |
| 145 | err = writer(file) |
| 146 | assertive.ErrorIsNil( |
| 147 | silentT, |
| 148 | err, |
| 149 | fmt.Sprintf("Filewriter failed while attempting to write to %q", pth), |
| 150 | ) |
| 151 | |
| 152 | return pth |
| 153 | } |
| 154 | |
| 155 | func (tp *temp) Dir(key ...string) string { |
| 156 | tp.t.Helper() |