summaryrefslogtreecommitdiff
path: root/integrationtests
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-11-02 08:11:40 +0200
committerPaul Buetow <paul@buetow.org>2021-11-02 08:11:40 +0200
commit1ec88deea93047a9d1a366e032b2a54aa3cd362b (patch)
tree465f30673aa097a2b369e7c3d2032b041ff4f8e6 /integrationtests
parent2e9ce81c47d45dd1f2c607df6e19bdfdc3bb3cc8 (diff)
Bugfix: Dealing correctly with files without newline characters, also add more tests
Diffstat (limited to 'integrationtests')
-rw-r--r--integrationtests/dcat1a.txt (renamed from integrationtests/dcat.txt)0
-rw-r--r--integrationtests/dcat1b.txt4
-rw-r--r--integrationtests/dcat1c.txt10
-rw-r--r--integrationtests/dcat1d.txt1
-rw-r--r--integrationtests/dcat_test.go55
5 files changed, 46 insertions, 24 deletions
diff --git a/integrationtests/dcat.txt b/integrationtests/dcat1a.txt
index 9e80424..9e80424 100644
--- a/integrationtests/dcat.txt
+++ b/integrationtests/dcat1a.txt
diff --git a/integrationtests/dcat1b.txt b/integrationtests/dcat1b.txt
new file mode 100644
index 0000000..658ee3b
--- /dev/null
+++ b/integrationtests/dcat1b.txt
@@ -0,0 +1,4 @@
+2 empty lines:
+
+
+line without newline
diff --git a/integrationtests/dcat1c.txt b/integrationtests/dcat1c.txt
new file mode 100644
index 0000000..f952bf8
--- /dev/null
+++ b/integrationtests/dcat1c.txt
@@ -0,0 +1,10 @@
+1 Sat 2 Oct 13:46:45 EEST 2021
+2 Sat 2 Oct 13:46:45 EEST 2021
+3 Sat 2 Oct 13:46:45 EEST 2021
+4 Sat 2 Oct 13:46:45 EEST 2021
+5 Sat 2 Oct 13:46:45 EEST 2021
+6 Sat 2 Oct 13:46:45 EEST 2021
+7 Sat 2 Oct 13:46:45 EEST 2021
+8 Sat 2 Oct 13:46:45 EEST 2021
+9 Sat 2 Oct 13:46:45 EEST 2021
+10 Sat 2 Oct 13:46:45 EEST 2021
diff --git a/integrationtests/dcat1d.txt b/integrationtests/dcat1d.txt
new file mode 100644
index 0000000..074c277
--- /dev/null
+++ b/integrationtests/dcat1d.txt
@@ -0,0 +1 @@
+single line without newline \ No newline at end of file
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)
}