summaryrefslogtreecommitdiff
path: root/integrationtests/dtailhealthcheck_test.go
blob: bb6c1463525ad69e5307469419bce1f49abf99a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package integrationtests

import (
	"context"
	"fmt"
	"os"
	"testing"
)

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(context.TODO(), stdoutFile, "../dtailhealthcheck")
	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(context.TODO(), stdoutFile,
		"../dtailhealthcheck", "--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 := "dtailhealthcheck3.stdout.tmp"
	expectedStdoutFile := "dtailhealthcheck3.expected"

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	_, _, _, err := startCommand(ctx,
		"../dserver",
		"--logger", "stdout",
		"--logLevel", "trace",
		"--port", "4242",
	)
	if err != nil {
		t.Error(err)
		return
	}

	_, err = runCommandRetry(ctx, 10, stdoutFile,
		"../dtailhealthcheck", "--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)
}