summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-24 20:49:08 +0300
committerPaul Buetow <paul@buetow.org>2025-06-24 20:49:08 +0300
commitb7a3e95e44cfcc324e5a54d6ba30fc0d83993dde (patch)
tree3fff6932e21669ae14d77f3a92f72c2fac0379bc
parentf96256a46390283bc0cd129154ce71702f2c70a0 (diff)
Improve integration tests with colored output tests
- Removed commented server mode code from TestDGrepStdin (stdin doesn't make sense with server mode) - Added TestDCat1Colors to test colored output in both serverless and server modes - Added TestDGrep1Colors to test colored output in both serverless and server modes - Fixed server metadata detection in colored output tests (look for "REMOTE" or "SERVER" without pipe) - Note: DMap colored output test was attempted but removed as DMap writes to CSV files, not stdout All integration tests now pass successfully. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
-rw-r--r--integrationtests/dcat_test.go123
-rw-r--r--integrationtests/dgrep_test.go138
-rw-r--r--integrationtests/dmap_test.go1
-rw-r--r--integrationtests/test.csv.query1
4 files changed, 257 insertions, 6 deletions
diff --git a/integrationtests/dcat_test.go b/integrationtests/dcat_test.go
index d0909d4..9b85278 100644
--- a/integrationtests/dcat_test.go
+++ b/integrationtests/dcat_test.go
@@ -101,6 +101,129 @@ func testDCat1WithServer(t *testing.T, inFile string) error {
return nil
}
+func TestDCat1Colors(t *testing.T) {
+ if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
+ t.Log("Skipping")
+ return
+ }
+
+ // Test in serverless mode
+ t.Run("Serverless", func(t *testing.T) {
+ testDCat1ColorsServerless(t)
+ })
+
+ // Test in server mode
+ t.Run("ServerMode", func(t *testing.T) {
+ testDCat1ColorsWithServer(t)
+ })
+}
+
+func testDCat1ColorsServerless(t *testing.T) {
+ inFile := "dcat1a.txt"
+ outFile := "dcat1colors.out"
+
+ // Run without --plain to get colored output
+ _, err := runCommand(context.TODO(), t, outFile,
+ "../dcat", "--cfg", "none", inFile)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ // Just verify it ran successfully and produced output
+ info, err := os.Stat(outFile)
+ if err != nil {
+ t.Error("Output file not created:", err)
+ return
+ }
+ if info.Size() == 0 {
+ t.Error("Output file is empty")
+ return
+ }
+
+ // Verify output contains ANSI color codes
+ content, err := os.ReadFile(outFile)
+ if err != nil {
+ t.Error("Failed to read output file:", err)
+ return
+ }
+ if !strings.Contains(string(content), "\033[") {
+ t.Error("Output does not contain ANSI color codes")
+ return
+ }
+
+ os.Remove(outFile)
+}
+
+func testDCat1ColorsWithServer(t *testing.T) {
+ inFile := "dcat1a.txt"
+ outFile := "dcat1colors.out"
+ port := getUniquePortNumber()
+ bindAddress := "localhost"
+
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ // Start dserver
+ _, _, _, err := startCommand(ctx, t,
+ "", "../dserver",
+ "--cfg", "none",
+ "--logger", "stdout",
+ "--logLevel", "error",
+ "--bindAddress", bindAddress,
+ "--port", fmt.Sprintf("%d", port),
+ )
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ // Give server time to start
+ time.Sleep(500 * time.Millisecond)
+
+ // Run without --plain and without --noColor to get colored output
+ _, err = runCommand(ctx, t, outFile,
+ "../dcat", "--cfg", "none",
+ "--servers", fmt.Sprintf("%s:%d", bindAddress, port),
+ "--files", inFile,
+ "--trustAllHosts")
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ cancel()
+
+ // Just verify it ran successfully and produced output
+ info, err := os.Stat(outFile)
+ if err != nil {
+ t.Error("Output file not created:", err)
+ return
+ }
+ if info.Size() == 0 {
+ t.Error("Output file is empty")
+ return
+ }
+
+ // In server mode, output should contain server metadata unless --plain is used
+ content, err := os.ReadFile(outFile)
+ if err != nil {
+ t.Error("Failed to read output file:", err)
+ return
+ }
+ // In server mode with colors, look for REMOTE or SERVER (without pipe as it may be colored)
+ if !strings.Contains(string(content), "REMOTE") && !strings.Contains(string(content), "SERVER") {
+ preview := string(content)
+ if len(preview) > 500 {
+ preview = preview[:500]
+ }
+ t.Errorf("Server mode output does not contain server metadata. First 500 chars:\n%s", preview)
+ return
+ }
+
+ os.Remove(outFile)
+}
+
func TestDCat2(t *testing.T) {
if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
return
diff --git a/integrationtests/dgrep_test.go b/integrationtests/dgrep_test.go
index 489d1f5..1da7e8f 100644
--- a/integrationtests/dgrep_test.go
+++ b/integrationtests/dgrep_test.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
+ "strings"
"testing"
"time"
@@ -104,6 +105,136 @@ func testDGrep1WithServer(t *testing.T) {
os.Remove(outFile)
}
+func TestDGrep1Colors(t *testing.T) {
+ if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
+ t.Log("Skipping")
+ return
+ }
+
+ // Test in serverless mode
+ t.Run("Serverless", func(t *testing.T) {
+ testDGrep1ColorsServerless(t)
+ })
+
+ // Test in server mode
+ t.Run("ServerMode", func(t *testing.T) {
+ testDGrep1ColorsWithServer(t)
+ })
+}
+
+func testDGrep1ColorsServerless(t *testing.T) {
+ inFile := "mapr_testdata.log"
+ outFile := "dgrep1colors.stdout.tmp"
+
+ // Run without --plain to get colored output
+ _, err := runCommand(context.TODO(), t, outFile,
+ "../dgrep",
+ "--cfg", "none",
+ "--grep", "1002-071947",
+ inFile)
+
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ // Verify it ran successfully and produced output
+ info, err := os.Stat(outFile)
+ if err != nil {
+ t.Error("Output file not created:", err)
+ return
+ }
+ if info.Size() == 0 {
+ t.Error("Output file is empty")
+ return
+ }
+
+ // Verify output contains ANSI color codes
+ content, err := os.ReadFile(outFile)
+ if err != nil {
+ t.Error("Failed to read output file:", err)
+ return
+ }
+ if !strings.Contains(string(content), "\033[") {
+ t.Error("Output does not contain ANSI color codes")
+ return
+ }
+
+ os.Remove(outFile)
+}
+
+func testDGrep1ColorsWithServer(t *testing.T) {
+ inFile := "mapr_testdata.log"
+ outFile := "dgrep1colors.stdout.tmp"
+ port := getUniquePortNumber()
+ bindAddress := "localhost"
+
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ // Start dserver
+ _, _, _, err := startCommand(ctx, t,
+ "", "../dserver",
+ "--cfg", "none",
+ "--logger", "stdout",
+ "--logLevel", "error",
+ "--bindAddress", bindAddress,
+ "--port", fmt.Sprintf("%d", port),
+ )
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ // Give server time to start
+ time.Sleep(500 * time.Millisecond)
+
+ // Run without --plain and without --noColor to get colored output
+ _, err = runCommand(ctx, t, outFile,
+ "../dgrep",
+ "--cfg", "none",
+ "--grep", "1002-071947",
+ "--servers", fmt.Sprintf("%s:%d", bindAddress, port),
+ "--trustAllHosts",
+ "--files", inFile)
+
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ cancel()
+
+ // Verify it ran successfully and produced output
+ info, err := os.Stat(outFile)
+ if err != nil {
+ t.Error("Output file not created:", err)
+ return
+ }
+ if info.Size() == 0 {
+ t.Error("Output file is empty")
+ return
+ }
+
+ // In server mode, output should contain server metadata
+ content, err := os.ReadFile(outFile)
+ if err != nil {
+ t.Error("Failed to read output file:", err)
+ return
+ }
+ // In server mode with colors, look for REMOTE or SERVER (without pipe as it may be colored)
+ if !strings.Contains(string(content), "REMOTE") && !strings.Contains(string(content), "SERVER") {
+ preview := string(content)
+ if len(preview) > 500 {
+ preview = preview[:500]
+ }
+ t.Errorf("Server mode output does not contain server metadata. First 500 chars:\n%s", preview)
+ return
+ }
+
+ os.Remove(outFile)
+}
+
func TestDGrep2(t *testing.T) {
if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
t.Log("Skipping")
@@ -399,15 +530,10 @@ func TestDGrepStdin(t *testing.T) {
return
}
- // Test in serverless mode
+ // Test in serverless mode only - stdin pipe doesn't make sense with server mode
t.Run("Serverless", func(t *testing.T) {
testDGrepStdinServerless(t)
})
-
- // Test in server mode - skip stdin pipe test as it hangs (similar to dmap)
- // t.Run("ServerMode", func(t *testing.T) {
- // testDGrepStdinWithServer(t)
- // })
}
func testDGrepStdinServerless(t *testing.T) {
diff --git a/integrationtests/dmap_test.go b/integrationtests/dmap_test.go
index ca1fddf..0db7982 100644
--- a/integrationtests/dmap_test.go
+++ b/integrationtests/dmap_test.go
@@ -192,6 +192,7 @@ func testDmap1WithServer(t *testing.T, query, subtestName string, usePipe bool)
return nil
}
+
func TestDMap2(t *testing.T) {
if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") {
t.Log("Skipping")
diff --git a/integrationtests/test.csv.query b/integrationtests/test.csv.query
new file mode 100644
index 0000000..4f57870
--- /dev/null
+++ b/integrationtests/test.csv.query
@@ -0,0 +1 @@
+from STATS select count($line) outfile test.csv \ No newline at end of file