@@ -29,6 +29,47 @@ type HealthTest struct {
29
29
expected string
30
30
}
31
31
32
+ func TestHealthCmd_Logstash6 (t * testing.T ) {
33
+ tests := []HealthTest {
34
+ {
35
+ name : "version-error" ,
36
+ server : httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
37
+ w .WriteHeader (http .StatusOK )
38
+ w .Write ([]byte (`{"host":"logstash","version":"foo"}` ))
39
+ })),
40
+ args : []string {"run" , "../main.go" , "health" },
41
+ expected : "UNKNOWN - Could not determine version" ,
42
+ },
43
+ {
44
+ name : "health-ok" ,
45
+ server : httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
46
+ w .WriteHeader (http .StatusOK )
47
+ w .Write ([]byte (`{"host":"logstash","version":"6.8.23","http_address":"0.0.0.0:9600","id":"123","name":"logstash","jvm":{"threads":{"count":1,"peak_count":2},"mem":{},"gc":{},"uptime_in_millis":123},"process":{},"events":{},"pipelines":{"main":{}},"reloads":{"failures":0,"successes":0},"os":{}}` ))
48
+ })),
49
+ args : []string {"run" , "../main.go" , "health" },
50
+ expected : "OK - Logstash is healthy" ,
51
+ },
52
+ }
53
+
54
+ for _ , test := range tests {
55
+ t .Run (test .name , func (t * testing.T ) {
56
+ defer test .server .Close ()
57
+
58
+ // We need the random Port extracted
59
+ u , _ := url .Parse (test .server .URL )
60
+ cmd := exec .Command ("go" , append (test .args , "--port" , u .Port ())... )
61
+ out , _ := cmd .CombinedOutput ()
62
+
63
+ actual := string (out )
64
+
65
+ if ! strings .Contains (actual , test .expected ) {
66
+ t .Error ("\n Actual: " , actual , "\n Expected: " , test .expected )
67
+ }
68
+
69
+ })
70
+ }
71
+ }
72
+
32
73
func TestHealthCmd_Logstash7 (t * testing.T ) {
33
74
tests := []HealthTest {
34
75
{
0 commit comments