diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2021-10-21 21:28:49 +0300 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2021-10-21 21:28:49 +0300 |
| commit | f4207a55f71bfbcfdc532d5cdd3befaa3474a157 (patch) | |
| tree | ea5e4a2d2a67035f645bdee496ae55a52034178a /integrationtests/dtailhealth_test.go | |
| parent | d80d6070557e3a800e3a54967af9eced518f116b (diff) | |
| parent | 739205206d63bf42f4e843b39d04d4c8cd8207c3 (diff) | |
merge develop
Diffstat (limited to 'integrationtests/dtailhealth_test.go')
| -rw-r--r-- | integrationtests/dtailhealth_test.go | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/integrationtests/dtailhealth_test.go b/integrationtests/dtailhealth_test.go new file mode 100644 index 0000000..8c0918f --- /dev/null +++ b/integrationtests/dtailhealth_test.go @@ -0,0 +1,95 @@ +package integrationtests + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/mimecast/dtail/internal/config" +) + +func TestDTailHealthCheck(t *testing.T) { + if !config.Env("DTAIL_RUN_INTEGRATION_TESTS") { + t.Log("Skipping") + return + } + stdoutFile := "dtailhealth.stdout.tmp" + expectedStdoutFile := "dtailhealth.expected" + + t.Log("Serverless check, is supposed to exit with warning state.") + exitCode, err := runCommand(context.TODO(), t, stdoutFile, "../dtailhealth") + if exitCode != 1 { + t.Error(fmt.Sprintf("Expected exit code '1' but got '%d': %v", exitCode, err)) + return + } + + if err := compareFiles(t, stdoutFile, expectedStdoutFile); err != nil { + t.Error(err) + return + } + os.Remove(stdoutFile) +} + +func TestDTailHealthCheck2(t *testing.T) { + if !config.Env("DTAIL_RUN_INTEGRATION_TESTS") { + t.Log("Skipping") + return + } + stdoutFile := "dtailhealth2.stdout.tmp" + expectedStdoutFile := "dtailhealth2.expected" + + t.Log("Negative test, is supposed to exit with a critical state.") + exitCode, err := runCommand(context.TODO(), t, stdoutFile, + "../dtailhealth", "--server", "example:1") + + if exitCode != 2 { + t.Error(fmt.Sprintf("Expected exit code '2' but got '%d': %v", exitCode, err)) + return + } + + if err := compareFiles(t, stdoutFile, expectedStdoutFile); err != nil { + t.Error(err) + return + } + + os.Remove(stdoutFile) +} + +func TestDTailHealthCheck3(t *testing.T) { + if !config.Env("DTAIL_RUN_INTEGRATION_TESTS") { + t.Log("Skipping") + return + } + stdoutFile := "dtailhealth3.stdout.tmp" + expectedStdoutFile := "dtailhealth3.expected" + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + _, _, _, err := startCommand(ctx, t, + "../dserver", + "--logger", "stdout", + "--logLevel", "trace", + "--bindAddress", "localhost", + "--port", "4242", + ) + if err != nil { + t.Error(err) + return + } + + _, err = runCommandRetry(ctx, t, 10, stdoutFile, + "../dtailhealth", "--server", "localhost:4242") + if err != nil { + t.Error(err) + return + } + + if err := compareFiles(t, stdoutFile, expectedStdoutFile); err != nil { + t.Error(err) + return + } + + os.Remove(stdoutFile) +} |
