summaryrefslogtreecommitdiff
path: root/integrationtests
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-09 21:10:29 +0300
committerPaul Buetow <paul@buetow.org>2021-10-10 13:36:41 +0300
commit97747ea0f3178f7f5890512d483fdccaa82846b0 (patch)
tree9ff1335ca26afc90e55fd6de416457e252d75a35 /integrationtests
parent7a7169791a64190e1002e38bc9c04ad0d5c1ce1f (diff)
vetting and linting and some code restyling
Diffstat (limited to 'integrationtests')
-rw-r--r--integrationtests/commons.go15
-rw-r--r--integrationtests/dcat_test.go4
-rw-r--r--integrationtests/dgrep_test.go8
-rw-r--r--integrationtests/dmap_test.go50
-rw-r--r--integrationtests/dtail_test.go4
-rw-r--r--integrationtests/dtailhealthcheck_test.go10
6 files changed, 70 insertions, 21 deletions
diff --git a/integrationtests/commons.go b/integrationtests/commons.go
index f96b532..2fdbfc3 100644
--- a/integrationtests/commons.go
+++ b/integrationtests/commons.go
@@ -15,10 +15,12 @@ import (
)
func runCommand(t *testing.T, cmd string, args []string, stdoutFile string) (int, error) {
- return runCommandContext(t, context.TODO(), cmd, args, stdoutFile)
+ return runCommandContext(context.TODO(), t, cmd, args, stdoutFile)
}
-func runCommandContext(t *testing.T, ctx context.Context, cmd string, args []string, stdoutFile string) (int, error) {
+func runCommandContext(ctx context.Context, t *testing.T, cmd string, args []string,
+ stdoutFile string) (int, error) {
+
if _, err := os.Stat(cmd); err != nil {
return -1, fmt.Errorf("No such binary %s, please compile first (%v)", cmd, err)
}
@@ -76,7 +78,8 @@ func compareFilesContents(t *testing.T, fileA, fileB string) error {
return fmt.Errorf("Files differ, line '%s' is missing in one of them", line)
}
if countA != countB {
- return fmt.Errorf("Files differ, count of line '%s' is %d in one but %d in another", line, countA, countB)
+ return fmt.Errorf("Files differ, count of line '%s' is %d in one but %d in another",
+ line, countA, countB)
}
}
return nil
@@ -92,11 +95,13 @@ func compareFilesContents(t *testing.T, fileA, fileB string) error {
}
// The mapreduce result can be in a different order each time (Golang maps are not sorted).
- t.Log(fmt.Sprintf("Checking whether %s has same lines as file %s (ignoring line order)", fileA, fileB))
+ t.Log(fmt.Sprintf("Checking whether %s has same lines as file %s (ignoring line order)",
+ fileA, fileB))
if err := compareMaps(a, b); err != nil {
return err
}
- t.Log(fmt.Sprintf("Checking whether %s has same lines as file %s (ignoring line order)", fileB, fileA))
+ t.Log(fmt.Sprintf("Checking whether %s has same lines as file %s (ignoring line order)",
+ fileB, fileA))
if err := compareMaps(b, a); err != nil {
return err
}
diff --git a/integrationtests/dcat_test.go b/integrationtests/dcat_test.go
index a164960..342ebd0 100644
--- a/integrationtests/dcat_test.go
+++ b/integrationtests/dcat_test.go
@@ -8,12 +8,12 @@ import (
func TestDCat(t *testing.T) {
testdataFile := "dcat.txt.expected"
stdoutFile := "dcat.out"
+ args := []string{"-spartan", testdataFile}
- if _, err := runCommand(t, "../dcat", []string{"-spartan", testdataFile}, stdoutFile); err != nil {
+ if _, err := runCommand(t, "../dcat", args, stdoutFile); err != nil {
t.Error(err)
return
}
-
if err := compareFiles(t, stdoutFile, testdataFile); err != nil {
t.Error(err)
return
diff --git a/integrationtests/dgrep_test.go b/integrationtests/dgrep_test.go
index 6a15ebd..4d54a2d 100644
--- a/integrationtests/dgrep_test.go
+++ b/integrationtests/dgrep_test.go
@@ -9,12 +9,12 @@ func TestDGrep(t *testing.T) {
inFile := "mapr_testdata.log"
stdoutFile := "dgrep.stdout.tmp"
expectedStdoutFile := "dgrep.txt.expected"
+ args := []string{"-spartan", "--grep", "20211002-071947", inFile}
- if _, err := runCommand(t, "../dgrep", []string{"-spartan", "--grep", "20211002-071947", inFile}, stdoutFile); err != nil {
+ if _, err := runCommand(t, "../dgrep", args, stdoutFile); err != nil {
t.Error(err)
return
}
-
if err := compareFiles(t, stdoutFile, expectedStdoutFile); err != nil {
t.Error(err)
return
@@ -26,12 +26,12 @@ func TestDGrep2(t *testing.T) {
inFile := "mapr_testdata.log"
stdoutFile := "dgrep2.stdout.tmp"
expectedStdoutFile := "dgrep2.txt.expected"
+ args := []string{"-spartan", "--grep", "20211002-071947", "--invert", inFile}
- if _, err := runCommand(t, "../dgrep", []string{"-spartan", "--grep", "20211002-071947", "--invert", inFile}, stdoutFile); err != nil {
+ if _, err := runCommand(t, "../dgrep", args, stdoutFile); err != nil {
t.Error(err)
return
}
-
if err := compareFiles(t, stdoutFile, expectedStdoutFile); err != nil {
t.Error(err)
return
diff --git a/integrationtests/dmap_test.go b/integrationtests/dmap_test.go
index b512985..f5c78e0 100644
--- a/integrationtests/dmap_test.go
+++ b/integrationtests/dmap_test.go
@@ -14,9 +14,12 @@ func TestDMap(t *testing.T) {
queryFile := fmt.Sprintf("%s.query", csvFile)
expectedQueryFile := "dmap.csv.query.expected"
- query := fmt.Sprintf("from STATS select count($line),last($time),avg($goroutines),min(concurrentConnections),max(lifetimeConnections) group by $hostname outfile %s", csvFile)
+ query := fmt.Sprintf("from STATS select count($line),last($time),"+
+ "avg($goroutines),min(concurrentConnections),max(lifetimeConnections) "+
+ "group by $hostname outfile %s", csvFile)
+ args := []string{"-query", query, inFile}
- if _, err := runCommand(t, "../dmap", []string{"-query", query, inFile}, stdoutFile); err != nil {
+ if _, err := runCommand(t, "../dmap", args, stdoutFile); err != nil {
t.Error(err)
return
}
@@ -42,9 +45,48 @@ func TestDMap2(t *testing.T) {
queryFile := fmt.Sprintf("%s.query", csvFile)
expectedQueryFile := "dmap2.csv.query.expected"
- query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),avg($goroutines),min($goroutines) group by $time order by count($time) outfile %s", csvFile)
+ query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
+ "avg($goroutines),min($goroutines) group by $time order by count($time) "+
+ "outfile %s", csvFile)
- if _, err := runCommand(t, "../dmap", []string{"-query", query, inFile}, stdoutFile); err != nil {
+ args := []string{"-query", query, inFile}
+ if _, err := runCommand(t, "../dmap", args, stdoutFile); err != nil {
+ t.Error(err)
+ return
+ }
+ if err := compareFilesContents(t, csvFile, expectedCsvFile); err != nil {
+ t.Error(err)
+ return
+ }
+ if err := compareFiles(t, queryFile, expectedQueryFile); err != nil {
+ t.Error(err)
+ return
+ }
+
+ os.Remove(stdoutFile)
+ os.Remove(csvFile)
+ os.Remove(queryFile)
+}
+
+func TestDMap3(t *testing.T) {
+ inFile := "mapr_testdata.log"
+ stdoutFile := "dmap3.stdout.tmp"
+ csvFile := "dmap3.csv.tmp"
+ expectedCsvFile := "dmap3.csv.expected"
+ queryFile := fmt.Sprintf("%s.query", csvFile)
+ expectedQueryFile := "dmap3.csv.query.expected"
+
+ query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
+ "avg($goroutines),min($goroutines) group by $time order by count($time) "+
+ "outfile %s", csvFile)
+
+ // Read many input files at once.
+ args := []string{"-query", query}
+ for i := 0; i < 100; i++ {
+ args = append(args, inFile)
+ }
+
+ if _, err := runCommand(t, "../dmap", args, stdoutFile); err != nil {
t.Error(err)
return
}
diff --git a/integrationtests/dtail_test.go b/integrationtests/dtail_test.go
index 9971f1a..36eadc0 100644
--- a/integrationtests/dtail_test.go
+++ b/integrationtests/dtail_test.go
@@ -8,8 +8,9 @@ import (
func TestDTailColorTable(t *testing.T) {
stdoutFile := "dtailcolortable.stdout.tmp"
expectedStdoutFile := "dtailcolortable.expected"
+ args := []string{"-colorTable"}
- if _, err := runCommand(t, "../dtail", []string{"-colorTable"}, stdoutFile); err != nil {
+ if _, err := runCommand(t, "../dtail", args, stdoutFile); err != nil {
t.Error(err)
return
}
@@ -17,6 +18,5 @@ func TestDTailColorTable(t *testing.T) {
t.Error(err)
return
}
-
os.Remove(stdoutFile)
}
diff --git a/integrationtests/dtailhealthcheck_test.go b/integrationtests/dtailhealthcheck_test.go
index 97fa5f2..d562239 100644
--- a/integrationtests/dtailhealthcheck_test.go
+++ b/integrationtests/dtailhealthcheck_test.go
@@ -30,9 +30,10 @@ func TestDTailHealthCheck(t *testing.T) {
func TestDTailHealthCheck2(t *testing.T) {
stdoutFile := "dtailhealthcheck2.stdout.tmp"
expectedStdoutFile := "dtailhealthcheck2.expected"
+ args := []string{"--server", "example:1"}
t.Log("Negative test, is supposed to exit with a critical state.")
- exitCode, err := runCommand(t, "../dtailhealthcheck", []string{"--server", "example:1"}, stdoutFile)
+ exitCode, err := runCommand(t, "../dtailhealthcheck", args, stdoutFile)
if exitCode != 2 {
t.Error(fmt.Sprintf("Expected exit code '2' but got '%d': %v", exitCode, err))
return
@@ -55,16 +56,17 @@ func TestDTailHealthCheck3(t *testing.T) {
defer cancel()
go func() {
- serverArgs := []string{"--logger", "stdout", "--logLevel", "trace", "--port", "4242"}
- runCommandContext(t, ctx, "../dserver", serverArgs, serverStdoutFile)
+ args := []string{"--logger", "stdout", "--logLevel", "trace", "--port", "4242"}
+ runCommandContext(ctx, t, "../dserver", args, serverStdoutFile)
}()
var err error
+ args := []string{"--server", "localhost:4242"}
for i := 0; i < 30; i++ {
t.Log("Waiting for dserver to start", i)
time.Sleep(time.Second)
var exitCode int
- if exitCode, err = runCommand(t, "../dtailhealthcheck", []string{"--server", "localhost:4242"}, stdoutFile); exitCode == 0 {
+ if exitCode, err = runCommand(t, "../dtailhealthcheck", args, stdoutFile); exitCode == 0 {
break
}
}