From 698fb76b98c46c677abe13fdc93afc6c4f38c39e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 14 Oct 2021 20:55:35 +0300 Subject: refactor --- integrationtests/dtailhealth_test.go | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 integrationtests/dtailhealth_test.go (limited to 'integrationtests/dtailhealth_test.go') 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) +} -- cgit v1.2.3 From b27fc108ecd6eead5c97cf6e894bf8d639fff75c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 15 Oct 2021 13:06:18 +0300 Subject: Execute test directories individually --- integrationtests/dtailhealth_test.go | 1 + 1 file changed, 1 insertion(+) (limited to 'integrationtests/dtailhealth_test.go') diff --git a/integrationtests/dtailhealth_test.go b/integrationtests/dtailhealth_test.go index a3c9478..87ed648 100644 --- a/integrationtests/dtailhealth_test.go +++ b/integrationtests/dtailhealth_test.go @@ -57,6 +57,7 @@ func TestDTailHealthCheck3(t *testing.T) { "../dserver", "--logger", "stdout", "--logLevel", "trace", + "--bindAddress", "localhost", "--port", "4242", ) if err != nil { -- cgit v1.2.3 From 860c41441b3bcf542b5701ae2257812879ce47b4 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 19 Oct 2021 19:01:12 +0300 Subject: Set DTAIL_RUN_INTEGRATIONT_TEST to yes for integration tests --- integrationtests/dtailhealth_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'integrationtests/dtailhealth_test.go') diff --git a/integrationtests/dtailhealth_test.go b/integrationtests/dtailhealth_test.go index 87ed648..8c0918f 100644 --- a/integrationtests/dtailhealth_test.go +++ b/integrationtests/dtailhealth_test.go @@ -5,9 +5,15 @@ import ( "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" @@ -26,6 +32,10 @@ func TestDTailHealthCheck(t *testing.T) { } func TestDTailHealthCheck2(t *testing.T) { + if !config.Env("DTAIL_RUN_INTEGRATION_TESTS") { + t.Log("Skipping") + return + } stdoutFile := "dtailhealth2.stdout.tmp" expectedStdoutFile := "dtailhealth2.expected" @@ -47,6 +57,10 @@ func TestDTailHealthCheck2(t *testing.T) { } func TestDTailHealthCheck3(t *testing.T) { + if !config.Env("DTAIL_RUN_INTEGRATION_TESTS") { + t.Log("Skipping") + return + } stdoutFile := "dtailhealth3.stdout.tmp" expectedStdoutFile := "dtailhealth3.expected" -- cgit v1.2.3