diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-24 20:09:49 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-24 20:09:49 +0300 |
| commit | d94d8eb55250acbd1785d076a3f96e52b4a8c52e (patch) | |
| tree | 4fea08393b23242a8f42407ffbd21a3d78545c20 /integrationtests | |
| parent | 2e0d60308722c44f11a613f9f6ad1e7d4b0df7fc (diff) | |
Add server mode tests to dtailhealth integration tests
- Update TestDTailHealth1 and TestDTailHealth2 to run in both serverless and server modes
- TestDTailHealth1 tests without --server flag (warning state expected)
- TestDTailHealth2 tests unreachable server (critical state expected)
- TestDTailHealthCheck3 restructured to follow same pattern (server mode only)
- All dtailhealth tests now pass in appropriate modes
- Added time import for server startup delay
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'integrationtests')
| -rw-r--r-- | integrationtests/dtailhealth_test.go | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/integrationtests/dtailhealth_test.go b/integrationtests/dtailhealth_test.go index 7946824..fc0a693 100644 --- a/integrationtests/dtailhealth_test.go +++ b/integrationtests/dtailhealth_test.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "testing" + "time" "github.com/mimecast/dtail/internal/config" ) @@ -14,6 +15,20 @@ func TestDTailHealth1(t *testing.T) { t.Log("Skipping") return } + + // Test in serverless mode + t.Run("Serverless", func(t *testing.T) { + testDTailHealth1Serverless(t) + }) + + // Test in server mode - this test checks when no servers are specified + // so server mode behavior should be the same + t.Run("ServerMode", func(t *testing.T) { + testDTailHealth1WithServer(t) + }) +} + +func testDTailHealth1Serverless(t *testing.T) { outFile := "dtailhealth1.stdout.tmp" expectedOutFile := "dtailhealth1.expected" @@ -31,11 +46,67 @@ func TestDTailHealth1(t *testing.T) { os.Remove(outFile) } +func testDTailHealth1WithServer(t *testing.T) { + outFile := "dtailhealth1.stdout.tmp" + expectedOutFile := "dtailhealth1.expected" + 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) + + t.Log("Server mode check without --server flag, is supposed to exit with warning state.") + // Run dtailhealth without specifying --server flag + exitCode, err := runCommand(ctx, t, outFile, "../dtailhealth") + if exitCode != 1 { + t.Errorf("Expected exit code '1' but got '%d': %v", exitCode, err) + return + } + + cancel() + + if err := compareFiles(t, outFile, expectedOutFile); err != nil { + t.Error(err) + return + } + os.Remove(outFile) +} + func TestDTailHealth2(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) { + testDTailHealth2Serverless(t) + }) + + // Test in server mode - testing unreachable server + t.Run("ServerMode", func(t *testing.T) { + testDTailHealth2WithServer(t) + }) +} + +func testDTailHealth2Serverless(t *testing.T) { outFile := "dtailhealth2.stdout.tmp" expectedOutFile := "dtailhealth2.expected" @@ -56,11 +127,65 @@ func TestDTailHealth2(t *testing.T) { os.Remove(outFile) } +func testDTailHealth2WithServer(t *testing.T) { + outFile := "dtailhealth2.stdout.tmp" + expectedOutFile := "dtailhealth2.expected" + 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) + + t.Log("Server mode negative test, checking unreachable server, is supposed to exit with a critical state.") + // Check an unreachable server (not the one we started) + exitCode, err := runCommand(ctx, t, outFile, + "../dtailhealth", "--server", "example:1") + + if exitCode != 2 { + t.Error(fmt.Sprintf("Expected exit code '2' but got '%d': %v", exitCode, err)) + return + } + + cancel() + + if err := compareFiles(t, outFile, expectedOutFile); err != nil { + t.Error(err) + return + } + + os.Remove(outFile) +} + func TestDTailHealthCheck3(t *testing.T) { if !config.Env("DTAIL_INTEGRATION_TEST_RUN_MODE") { t.Log("Skipping") return } + + // This test only makes sense with a server + t.Run("ServerMode", func(t *testing.T) { + testDTailHealthCheck3WithServer(t) + }) +} + +func testDTailHealthCheck3WithServer(t *testing.T) { outFile := "dtailhealth3.stdout.tmp" port := getUniquePortNumber() bindAddress := "localhost" |
