diff options
Diffstat (limited to 'integrationtests')
| -rw-r--r-- | integrationtests/dmap5.csv.expected | 2 | ||||
| -rw-r--r-- | integrationtests/dmap5.csv.in | 4 | ||||
| -rw-r--r-- | integrationtests/dmap5.csv.query.expected | 1 | ||||
| -rw-r--r-- | integrationtests/dmap_test.go | 57 |
4 files changed, 64 insertions, 0 deletions
diff --git a/integrationtests/dmap5.csv.expected b/integrationtests/dmap5.csv.expected new file mode 100644 index 0000000..1323a61 --- /dev/null +++ b/integrationtests/dmap5.csv.expected @@ -0,0 +1,2 @@ +sum($timecount),last($time),min($min_goroutines) +63.000000,1002-071143,12.000000 diff --git a/integrationtests/dmap5.csv.in b/integrationtests/dmap5.csv.in new file mode 100644 index 0000000..98c7763 --- /dev/null +++ b/integrationtests/dmap5.csv.in @@ -0,0 +1,4 @@ +count($time),$time,max($goroutines),avg($goroutines),min($goroutines) +23,1002-071147,16.000000,14.391304,12.000000 +20,1002-071213,17.000000,14.100000,12.000000 +20,1002-071143,17.000000,15.000000,13.000000 diff --git a/integrationtests/dmap5.csv.query.expected b/integrationtests/dmap5.csv.query.expected new file mode 100644 index 0000000..2d1723c --- /dev/null +++ b/integrationtests/dmap5.csv.query.expected @@ -0,0 +1 @@ +select sum($timecount),last($time),min($min_goroutines), group by $hostname set $timecount = `count($time)`, $time = `$time`, $min_goroutines = `min($goroutines)` logformat csv outfile dmap5.csv.tmp
\ No newline at end of file diff --git a/integrationtests/dmap_test.go b/integrationtests/dmap_test.go index a378fb5..f772243 100644 --- a/integrationtests/dmap_test.go +++ b/integrationtests/dmap_test.go @@ -245,3 +245,60 @@ func TestDMap4Append(t *testing.T) { os.Remove(csvFile) os.Remove(queryFile) } + +func TestDMap5CSV(t *testing.T) { + if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") { + t.Log("Skipping") + return + } + inFile := "dmap5.csv.in" + outFile := "dmap5.stdout.tmp" + csvFile := "dmap5.csv.tmp" + expectedCsvFile := "dmap5.csv.expected" + queryFile := fmt.Sprintf("%s.query", csvFile) + expectedQueryFile := "dmap5.csv.query.expected" + + // Delete in case it exists already. Otherwise, test will fail. + os.Remove(csvFile) + + query := fmt.Sprintf("select sum($timecount),last($time),min($min_goroutines),"+ + " group by $hostname"+ + " set $timecount = `count($time)`, $time = `$time`, $min_goroutines = `min($goroutines)`"+ + " logformat csv outfile %s", csvFile) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + // Run dmap command twice, it should append in the 2nd iteration the new results to the already existing + // file as we specified "outfile append". That works transparently for any mapreduce query + // (e.g. also for the dtail command in streaming mode). But it is easier to test with the dmap + // command. + for i := 0; i < 2; i++ { + stdoutCh, stderrCh, cmdErrCh, err := startCommand(ctx, t, + "", "../dmap", + "--query", query, + "--cfg", "none", + "--logger", "stdout", + "--logLevel", "info", + "--noColor", inFile) + + if err != nil { + t.Error(err) + return + } + waitForCommand(ctx, t, stdoutCh, stderrCh, cmdErrCh) + } + + 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(outFile) + os.Remove(csvFile) + os.Remove(queryFile) +} |
