summaryrefslogtreecommitdiff
path: root/integrationtests/dcat_test.go
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 /integrationtests/dcat_test.go
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>
Diffstat (limited to 'integrationtests/dcat_test.go')
-rw-r--r--integrationtests/dcat_test.go123
1 files changed, 123 insertions, 0 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