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

Function TestCloseFiles

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

Source from the content-addressed store, hash-verified

329}
330
331func TestCloseFiles(t *testing.T) {
332 tests := []struct {
333 name string // test name
334 fnames []string // fname to create
335 close []int // indeces of file to close
336 }{
337 {
338 name: "good 1",
339 fnames: []string{"test0"},
340 close: []int{}, // want no error
341 },
342 {
343 name: "good 2",
344 fnames: []string{"test0", "test1"},
345 },
346 {
347 name: "good 3",
348 fnames: []string{"test0", "test1", "test2"},
349 },
350 {
351 name: "bad 1",
352 fnames: []string{"test0", "test1", "test2"},
353 close: []int{0}, // want error
354 },
355 {
356 name: "bad 2",
357 fnames: []string{"test0", "test1", "test2"},
358 close: []int{1},
359 },
360 {
361 name: "bad 3",
362 fnames: []string{"test0", "test1", "test2"},
363 close: []int{2},
364 },
365 {
366 name: "bad 1,3",
367 fnames: []string{"test0", "test1", "test2"},
368 close: []int{1, 2},
369 },
370 }
371 for _, tt := range tests {
372 t.Run(tt.name, func(t *testing.T) {
373 dir := t.TempDir()
374
375 files := make([]*os.File, 0, 3)
376 for _, fname := range tt.fnames {
377 f, _ := os.OpenFile(filepath.Join(dir, fname), os.O_CREATE|os.O_RDWR, 0)
378 files = append(files, f)
379 }
380
381 for _, i := range tt.close {
382 files[i].Close()
383 }
384
385 err := closeFiles(files...)
386
387 // Check returned error
388 if len(tt.close) == 0 {

Callers

nothing calls this directly

Calls 4

closeFilesFunction · 0.85
RunMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected