summaryrefslogtreecommitdiff
path: root/integrationtests-old/dserver_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-24 18:29:13 +0300
committerPaul Buetow <paul@buetow.org>2025-06-24 18:29:13 +0300
commit61b2a90aefee82da19ea5b388fb6112760833d97 (patch)
treeb53b04f296434afc9a71d5702363b6532d73f85c /integrationtests-old/dserver_test.go
parentd32f586ad7340db2b108702b69201733c2ce099f (diff)
Fix dcat tests for server mode and --plain flag handling
- Update dcat tests to use comma-separated file lists in server mode - Fix basehandler.go to properly respect --plain flag for server messages - Skip empty server messages when in plain mode - Add separate expected output file for TestDCatColors server mode - All dcat integration tests now pass in both serverless and server modes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'integrationtests-old/dserver_test.go')
-rw-r--r--integrationtests-old/dserver_test.go129
1 files changed, 129 insertions, 0 deletions
diff --git a/integrationtests-old/dserver_test.go b/integrationtests-old/dserver_test.go
new file mode 100644
index 0000000..eaca23b
--- /dev/null
+++ b/integrationtests-old/dserver_test.go
@@ -0,0 +1,129 @@
+package integrationtests
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/mimecast/dtail/internal/config"
+)
+
+func TestDServer1(t *testing.T) {
+ if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
+ t.Log("Skipping")
+ return
+ }
+ // Testing a scheduled query.
+
+ csvFile := "dserver1.csv"
+ expectedCsvFile := "dserver1.csv.expected"
+ queryFile := fmt.Sprintf("%s.query", csvFile)
+ expectedQueryFile := "dserver1.csv.query.expected"
+
+ // In case files still exists from previous test run.
+ os.Remove(csvFile)
+ os.Remove(queryFile)
+
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ stdoutCh, stderrCh, cmdErrCh, err := startCommand(ctx, t,
+ "", "../dserver",
+ "--cfg", "dserver1.cfg",
+ "--logger", "stdout",
+ "--logLevel", "debug",
+ "--bindAddress", "127.0.0.1",
+ "--shutdownAfter", "10",
+ "--port", fmt.Sprintf("%d", getUniquePortNumber()),
+ )
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ waitForCommand(ctx, t, stdoutCh, stderrCh, cmdErrCh)
+
+ if err := compareFiles(t, csvFile, expectedCsvFile); err != nil {
+ t.Error(err)
+ return
+ }
+ if err := compareFiles(t, queryFile, expectedQueryFile); err != nil {
+ t.Error(err)
+ return
+ }
+
+ os.Remove(csvFile)
+ os.Remove(queryFile)
+}
+
+func TestDServer2(t *testing.T) {
+ if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
+ t.Log("Skipping")
+ return
+ }
+
+ // Testing a continious query.
+
+ inFile := "dserver2.log"
+ csvFile := "dserver2.csv"
+ expectedCsvFile := "dserver2.csv.expected"
+ queryFile := fmt.Sprintf("%s.query", csvFile)
+ expectedQueryFile := "dserver2.csv.query.expected"
+
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ fd, err := os.Create(inFile)
+ if err != nil {
+ t.Error(err)
+ }
+ defer fd.Close()
+
+ go func() {
+ for {
+ select {
+ case <-time.After(time.Second):
+ parts := []string{"INFO", "19801011-424242", "1", "dserver_test.go",
+ "1", "1", "1", "1.0", "1m", "MAPREDUCE:INTEGRATIONTEST",
+ "foo=1", "bar=42"}
+ _, _ = fd.WriteString(strings.Join(parts, "|"))
+ _, _ = fd.WriteString("\n")
+ case <-ctx.Done():
+ return
+ }
+ }
+ }()
+
+ stdoutCh, stderrCh, cmdErrCh, err := startCommand(ctx, t,
+ "", "../dserver",
+ "--cfg", "dserver2.cfg",
+ "--logger", "stdout",
+ "--logLevel", "debug",
+ "--bindAddress", "127.0.0.1",
+ "--shutdownAfter", "10",
+ "--port", fmt.Sprintf("%d", getUniquePortNumber()),
+ )
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ waitForCommand(ctx, t, stdoutCh, stderrCh, cmdErrCh)
+ cancel()
+
+ if err := compareFiles(t, csvFile, expectedCsvFile); err != nil {
+ t.Error(err)
+ return
+ }
+ if err := compareFiles(t, queryFile, expectedQueryFile); err != nil {
+ t.Error(err)
+ return
+ }
+
+ os.Remove(inFile)
+ os.Remove(csvFile)
+ os.Remove(queryFile)
+}