summaryrefslogtreecommitdiff
path: root/integrationtests/dcat_test.go
blob: b2a041ce96ad6cb291b2c04b11d9289a95cf8dd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package integrationtests

import (
	"context"
	"os"
	"testing"

	"github.com/mimecast/dtail/internal/config"
)

func TestDCat1(t *testing.T) {
	if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
		t.Log("Skipping")
		return
	}

	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 {
		return err
	}
	if err := compareFiles(t, outFile, inFile); err != nil {
		return err
	}

	os.Remove(outFile)
	return nil
}

func TestDCat2(t *testing.T) {
	if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
		return
	}
	inFile := "dcat2.txt"
	expectedFile := "dcat2.txt.expected"
	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, inFile)
	}

	_, err := runCommand(context.TODO(), t, outFile, "../dcat", args...)
	if err != nil {
		t.Error(err)
		return
	}

	if err := compareFilesContents(t, outFile, expectedFile); err != nil {
		t.Error(err)
		return
	}

	os.Remove(outFile)
}

func TestDCat3(t *testing.T) {
	if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
		return
	}
	inFile := "dcat3.txt"
	expectedFile := "dcat3.txt.expected"
	outFile := "dcat3.out"

	args := []string{"--plain", "--logLevel", "error", "--cfg", "none", inFile}

	// Notice, with DTAIL_INTEGRATION_TEST_RUN_MODE the DTail max line length is set
	// to 1024!
	_, err := runCommand(context.TODO(), t, outFile, "../dcat", args...)
	if err != nil {
		t.Error(err)
		return
	}

	if err := compareFilesContents(t, outFile, expectedFile); err != nil {
		t.Error(err)
		return
	}

	os.Remove(outFile)
}

func TestDCatColors(t *testing.T) {
	if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
		return
	}

	inFile := "dcatcolors.txt"
	outFile := "dcatcolors.out"
	expectedFile := "dcatcolors.expected"

	_, err := runCommand(context.TODO(), t, outFile,
		"../dcat", "--logLevel", "error", "--cfg", "none", inFile)

	if err != nil {
		t.Error(err)
		return
	}

	if err := compareFiles(t, outFile, expectedFile); err != nil {
		t.Error(err)
		return
	}

	os.Remove(outFile)
}