From 1ec88deea93047a9d1a366e032b2a54aa3cd362b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 2 Nov 2021 08:11:40 +0200 Subject: Bugfix: Dealing correctly with files without newline characters, also add more tests --- integrationtests/dcat_test.go | 55 ++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'integrationtests/dcat_test.go') diff --git a/integrationtests/dcat_test.go b/integrationtests/dcat_test.go index 124cb62..bef5db2 100644 --- a/integrationtests/dcat_test.go +++ b/integrationtests/dcat_test.go @@ -8,57 +8,64 @@ import ( "github.com/mimecast/dtail/internal/config" ) -func TestDCat(t *testing.T) { +func TestDCat1(t *testing.T) { if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") { t.Log("Skipping") return } - testdataFile := "dcat.txt" - stdoutFile := "dcat.out" - _, err := runCommand(context.TODO(), t, stdoutFile, - "../dcat", "--plain", "--cfg", "none", testdataFile) + inFiles := []string{"dcat1a.txt", "dcat1b.txt", "dcat1c.txt", "dcat1d.txt"} + for _, inFile := range inFiles { + if err := testDCat1(t, inFile); err != nil { + t.Error(err) + return + } + } +} +func testDCat1(t *testing.T, inFile string) error { + outFile := "dcat1.out" + + _, err := runCommand(context.TODO(), t, outFile, + "../dcat", "--plain", "--cfg", "none", inFile) if err != nil { - t.Error(err) - return + return err } - - if err := compareFiles(t, stdoutFile, testdataFile); err != nil { - t.Error(err) - return + if err := compareFiles(t, outFile, inFile); err != nil { + return err } - os.Remove(stdoutFile) + os.Remove(outFile) + return nil } func TestDCat2(t *testing.T) { if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") { return } - testdataFile := "dcat2.txt" + inFile := "dcat2.txt" expectedFile := "dcat2.txt.expected" - stdoutFile := "dcat2.out" + outFile := "dcat2.out" args := []string{"--plain", "--logLevel", "error", "--cfg", "none"} // Cat file 100 times in one session. for i := 0; i < 100; i++ { - args = append(args, testdataFile) + args = append(args, inFile) } - _, err := runCommand(context.TODO(), t, stdoutFile, "../dcat", args...) + _, err := runCommand(context.TODO(), t, outFile, "../dcat", args...) if err != nil { t.Error(err) return } - if err := compareFilesContents(t, stdoutFile, expectedFile); err != nil { + if err := compareFilesContents(t, outFile, expectedFile); err != nil { t.Error(err) return } - os.Remove(stdoutFile) + os.Remove(outFile) } func TestDCatColors(t *testing.T) { @@ -66,22 +73,22 @@ func TestDCatColors(t *testing.T) { return } - testdataFile := "dcatcolors.txt" - stdoutFile := "dcatcolors.out" + inFile := "dcatcolors.txt" + outFile := "dcatcolors.out" expectedFile := "dcatcolors.expected" - _, err := runCommand(context.TODO(), t, stdoutFile, - "../dcat", "--logLevel", "error", "--cfg", "none", testdataFile) + _, err := runCommand(context.TODO(), t, outFile, + "../dcat", "--logLevel", "error", "--cfg", "none", inFile) if err != nil { t.Error(err) return } - if err := compareFiles(t, stdoutFile, expectedFile); err != nil { + if err := compareFiles(t, outFile, expectedFile); err != nil { t.Error(err) return } - os.Remove(stdoutFile) + os.Remove(outFile) } -- cgit v1.2.3