-
Notifications
You must be signed in to change notification settings - Fork 2
/
serve_test.go
50 lines (43 loc) · 1.22 KB
/
serve_test.go
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
package goss
import (
"github.com/SimonBaeumer/goss/outputs"
"github.com/SimonBaeumer/goss/resource"
"github.com/patrickmn/go-cache"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"sync"
"testing"
"time"
)
func TestHealthHandler_Serve(t *testing.T) {
req, err := http.NewRequest("GET", "/healthz", nil)
if err != nil {
t.Fatal(err)
}
cmdResource := &resource.Command{
Command: "echo hello",
Title: "echo hello",
ExitStatus: 0,
}
h := HealthHandler{
Cache: cache.New(time.Duration(50), time.Duration(50)),
Outputer: outputs.GetOutputer("documentation"),
MaxConcurrent: 1,
ListenAddr: "9999",
ContentType: "application/json",
GossMu: &sync.Mutex{},
GossConfig: GossConfig{
Commands: resource.CommandMap{"echo hello": cmdResource},
},
}
rr := httptest.NewRecorder()
h.ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusOK {
t.Errorf("Health check failed!")
}
assert.Equal(t, http.StatusOK, rr.Code)
assert.Contains(t, rr.Body.String(), "Title: echo hello")
assert.Contains(t, rr.Body.String(), "Command: echo hello: exit-status: matches expectation: [0]")
assert.Contains(t, rr.Body.String(), "Count: 1, Failed: 0, Skipped: 0")
}