(t *testing.T)
| 650 | } |
| 651 | |
| 652 | func TestFileWriterDiscardEmptyFiles(t *testing.T) { |
| 653 | defer testutil.DisableLogging()() |
| 654 | |
| 655 | tmpDir := t.TempDir() |
| 656 | toml := ` |
| 657 | [csv] |
| 658 | field_separator="," |
| 659 | |
| 660 | [fields] |
| 661 | names = ["kind", "digits", "first", "last", "email", "state"] |
| 662 | |
| 663 | [input] |
| 664 | name = "channel" |
| 665 | |
| 666 | [output] |
| 667 | fields = [] |
| 668 | name = "filewriter" |
| 669 | procs = 1 |
| 670 | [output.config] |
| 671 | pathstring = %q |
| 672 | rotateInterval = "10ms" |
| 673 | discardEmptyFiles = true |
| 674 | ` |
| 675 | if !testing.Verbose() { |
| 676 | defer testutil.LessLogging()() |
| 677 | } |
| 678 | |
| 679 | toml = fmt.Sprintf(toml, filepath.Join(tmpDir, "file-{{.Hour}}-{{.Minute}}-{{.Second}}-{{.Rotation}}.log.gz")) |
| 680 | cfg, err := baker.NewConfigFromToml(strings.NewReader(toml), |
| 681 | baker.Components{ |
| 682 | Inputs: []baker.InputDesc{inputtest.ChannelDesc}, |
| 683 | Outputs: []baker.OutputDesc{output.FileWriterDesc}, |
| 684 | }) |
| 685 | if err != nil { |
| 686 | t.Fatal(err) |
| 687 | } |
| 688 | topo, err := baker.NewTopologyFromConfig(cfg) |
| 689 | if err != nil { |
| 690 | t.Fatal(err) |
| 691 | } |
| 692 | |
| 693 | in := topo.Input.(*inputtest.Channel) |
| 694 | go func() { |
| 695 | *in <- baker.Data{Bytes: []byte(";;;;\n")} |
| 696 | time.Sleep(200 * time.Millisecond) |
| 697 | *in <- baker.Data{Bytes: []byte(";;;;\n")} |
| 698 | time.Sleep(200 * time.Millisecond) |
| 699 | |
| 700 | close(*in) |
| 701 | }() |
| 702 | |
| 703 | topo.Start() |
| 704 | topo.Wait() |
| 705 | |
| 706 | files, err := dirtree.List(tmpDir, dirtree.Type("f"), dirtree.ModeAll) |
| 707 | if err != nil { |
| 708 | t.Fatal(err) |
| 709 | } |
nothing calls this directly
no test coverage detected