diff options
| author | Paul Buetow <paul@buetow.org> | 2021-10-14 20:55:35 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2021-10-15 08:40:54 +0300 |
| commit | 698fb76b98c46c677abe13fdc93afc6c4f38c39e (patch) | |
| tree | ac6884ea24d262c36d1f3b6e12a6adf2ba7acb8b /integrationtests/dtailhealth_test.go | |
| parent | 06ece112c0dd20c0c211c538216fe64ebe4045c9 (diff) | |
refactor
Diffstat (limited to 'integrationtests/dtailhealth_test.go')
| -rw-r--r-- | integrationtests/dtailhealth_test.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/integrationtests/dtailhealth_test.go b/integrationtests/dtailhealth_test.go new file mode 100644 index 0000000..a3c9478 --- /dev/null +++ b/integrationtests/dtailhealth_test.go @@ -0,0 +1,80 @@ +package integrationtests + +import ( + "context" + "fmt" + "os" + "testing" +) + +func TestDTailHealthCheck(t *testing.T) { + 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) { + 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) { + stdoutFile := "dtailhealth3.stdout.tmp" + expectedStdoutFile := "dtailhealth3.expected" + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + _, _, _, err := startCommand(ctx, t, + "../dserver", + "--logger", "stdout", + "--logLevel", "trace", + "--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) +} |
