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

Function testFileWriterIntegrationCheckRecords

output/filewriter_test.go:325–371  ·  view source on GitHub ↗

testFileWriterIntegrationCheckRecords builds and run a topology reading from testdata/filewriter/input.csv.log.zst and using the FileWriter output, configured with the given pathString (in pathString, "TMPDIR" gets replaced at runtime by the test case temporary directory). Once the topology exits,

(t *testing.T, pathString string, procs int, rotate time.Duration)

Source from the content-addressed store, hash-verified

323// is useful when the filenames and their content is not expected to be
324// deterministic.
325func testFileWriterIntegrationCheckRecords(t *testing.T, pathString string, procs int, rotate time.Duration) {
326 tmpDir := t.TempDir()
327 decompressed := testFileWriterIntegration(t, tmpDir, pathString, procs, rotate)
328
329 // Create a buffer with all the records in ascending order, separated by /n
330 var records []string
331 for _, name := range decompressed {
332 f, err := os.Open(name)
333 if err != nil {
334 t.Fatal(err)
335 }
336 scan := bufio.NewScanner(f)
337 for scan.Scan() {
338 records = append(records, scan.Text())
339 }
340 f.Close()
341 }
342 sort.Strings(records)
343
344 var out []byte
345 for _, rec := range records {
346 out = append(out, rec...)
347 out = append(out, '\n')
348 }
349
350 testutil.DiffWithGolden(t, out, filepath.Join("testdata", "filewriter", "input.sorted.golden"))
351 if t.Failed() {
352 tmp, err := os.MkdirTemp(os.TempDir(), t.Name())
353 if err != nil {
354 t.Fatal(err)
355 }
356
357 dirCpy := filepath.Join(tmp, "outdir")
358 csvCpy := filepath.Join(tmp, "sorted.csv")
359 if err := os.Mkdir(dirCpy, 0777); err != nil {
360 t.Fatal(err)
361 }
362
363 fmt.Printf("ERROR: copying data for failure investigation in %s\n\t- output directory copy: ./outdir\n\t- incorrect sorted buffer: ./sorted.csv\n\n", tmp)
364 if err := testutil.CopyDirectory(tmpDir, dirCpy); err != nil {
365 t.Fatal(err)
366 }
367 if err := os.WriteFile(csvCpy, out, os.ModePerm); err != nil {
368 t.Fatal(err)
369 }
370 }
371}
372
373func testFileWriterIntegration(t *testing.T, tmpDir, pathString string, procs int, rotate time.Duration) []string {
374 // This test uses a randomly generated input CSV file.

Calls 4

DiffWithGoldenFunction · 0.92
CopyDirectoryFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected