diff options
Diffstat (limited to 'integrationtests/dtailhealthcheck_test.go')
| -rw-r--r-- | integrationtests/dtailhealthcheck_test.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/integrationtests/dtailhealthcheck_test.go b/integrationtests/dtailhealthcheck_test.go new file mode 100644 index 0000000..97fa5f2 --- /dev/null +++ b/integrationtests/dtailhealthcheck_test.go @@ -0,0 +1,83 @@ +package integrationtests + +import ( + "context" + "fmt" + "os" + "testing" + "time" +) + +func TestDTailHealthCheck(t *testing.T) { + stdoutFile := "dtailhealthcheck.stdout.tmp" + expectedStdoutFile := "dtailhealthcheck.expected" + + t.Log("Serverless check, is supposed to exit with warning state.") + exitCode, err := runCommand(t, "../dtailhealthcheck", []string{}, stdoutFile) + 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) { + stdoutFile := "dtailhealthcheck2.stdout.tmp" + expectedStdoutFile := "dtailhealthcheck2.expected" + + t.Log("Negative test, is supposed to exit with a critical state.") + exitCode, err := runCommand(t, "../dtailhealthcheck", []string{"--server", "example:1"}, stdoutFile) + 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) { + stdoutFile := "dtailhealthcheck3.stdout.tmp" + serverStdoutFile := "dtailhealthcheck3.dserver.stdout.tmp" + expectedStdoutFile := "dtailhealthcheck3.expected" + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + go func() { + serverArgs := []string{"--logger", "stdout", "--logLevel", "trace", "--port", "4242"} + runCommandContext(t, ctx, "../dserver", serverArgs, serverStdoutFile) + }() + + var err error + for i := 0; i < 30; i++ { + t.Log("Waiting for dserver to start", i) + time.Sleep(time.Second) + var exitCode int + if exitCode, err = runCommand(t, "../dtailhealthcheck", []string{"--server", "localhost:4242"}, stdoutFile); exitCode == 0 { + break + } + } + if err != nil { + t.Error(err) + return + } + + if err := compareFiles(t, stdoutFile, expectedStdoutFile); err != nil { + t.Error(err) + return + } + + os.Remove(serverStdoutFile) + os.Remove(stdoutFile) +} |
