-
Notifications
You must be signed in to change notification settings - Fork 0
/
probe_test.go
56 lines (50 loc) · 997 Bytes
/
probe_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
51
52
53
54
55
56
package probe_test
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/keloran/go-probe"
"github.com/stretchr/testify/assert"
)
func TestProbe(t *testing.T) {
tests := []struct {
expect probe.Healthy
err error
}{
{
expect: probe.Healthy{
Status: "pass",
},
err: nil,
},
}
for _, test := range tests {
resp, err := probe.Probe()
assert.Equal(t, test.err, err)
assert.Equal(t, test.expect, resp)
}
}
func TestHTTP(t *testing.T) {
tests := []struct {
expect probe.Healthy
}{
{
expect: probe.Healthy{
Status: "pass",
},
},
}
for _, test := range tests {
request, _ := http.NewRequest("GET", "/", bytes.NewBuffer([]byte{}))
response := httptest.NewRecorder()
probe.HTTP(response, request)
assert.Equal(t, 200, response.Code)
body, _ := ioutil.ReadAll(response.Body)
healthy := probe.Healthy{}
_ = json.Unmarshal(body, &healthy)
assert.Equal(t, test.expect, healthy)
}
}