MCPcopy Create free account
hub / github.com/AdRoll/baker / TestSplitWriterErr

Function TestSplitWriterErr

pkg/splitwriter/split_writer_test.go:208–329  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

206}
207
208func TestSplitWriterErr(t *testing.T) {
209 type swConf struct {
210 path string // path to file
211 maxsize, bufsize int // splitWriter parameters
212 data string // data to write in fname
213 }
214 initSplitWriter := func(t *testing.T, cf swConf) io.WriteCloser {
215 w, err := New(cf.path, int64(cf.maxsize), int64(cf.bufsize))
216 if err != nil {
217 t.Fatal(err)
218 }
219 if _, err := w.Write([]byte(cf.data)); err != nil {
220 t.Fatal(err)
221 }
222 return w
223 }
224
225 t.Run("doFirstSplit f1 error ", func(t *testing.T) {
226 dir := t.TempDir()
227
228 cfg := swConf{
229 path: filepath.Join(dir, "big-file-1-split"),
230 maxsize: 12,
231 bufsize: 4,
232 data: "012\n34567890123",
233 }
234 w := initSplitWriter(t, cfg)
235
236 // Create the first part whitout write permission
237 f1, _ := os.OpenFile(cfg.path+"-part-1", os.O_CREATE, 0444)
238 f1.Close()
239
240 if err := w.Close(); err == nil {
241 t.Errorf("get nil, want error")
242 }
243
244 // Check that all files where closed
245 if err := os.RemoveAll(dir); err != nil {
246 t.Fatal(err)
247 }
248 })
249
250 t.Run("doFirstSplit f2 err", func(t *testing.T) {
251 dir := t.TempDir()
252
253 cfg := swConf{
254 path: filepath.Join(dir, "big-file-1-split"),
255 maxsize: 12,
256 bufsize: 4,
257 data: "012\n34567890123",
258 }
259 w := initSplitWriter(t, cfg)
260
261 // Create the second part whitout write permission
262 f2, _ := os.OpenFile(cfg.path+"-part-2", os.O_CREATE, 0444)
263 f2.Close()
264
265 if err := w.Close(); err == nil {

Callers

nothing calls this directly

Calls 4

NewFunction · 0.70
RunMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected