-
Notifications
You must be signed in to change notification settings - Fork 4
/
layer7_health_check_test.go
76 lines (72 loc) · 1.79 KB
/
layer7_health_check_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package gtm_test
import (
"errors"
"net/http"
"testing"
"github.com/datianshi/simple-cf-gtm"
. "github.com/datianshi/simple-cf-gtm"
"github.com/datianshi/simple-cf-gtm/fakes"
. "github.com/onsi/gomega"
"github.com/sclevine/spec"
)
func testLayer7HealthCheck(t *testing.T, when spec.G, it spec.S) {
when("test layer 7 health check", func() {
var (
check *fakes.FakeHttpCheckClient
schema string
path string
statusCode int
checkMethod HealthCheckMethod
ip gtm.IP
)
it.Before(func() {
check = &fakes.FakeHttpCheckClient{}
schema = "http"
path = "/health"
statusCode = 200
checkMethod = Layer7HealthCheck(check, schema, path, statusCode)
ip = gtm.IP{
Address: "x.x.x.x",
Host: "abc.xip.io",
}
})
when("http client return an error", func() {
it.Before(func() {
check.GetStub = func(url string) (*http.Response, error) {
return nil, errors.New("")
}
})
it("Should call the correct url", func() {
checkMethod(ip)
Ω(check.GetArgsForCall(0)).Should(Equal("http://abc.xip.io/health"))
})
it("Should return the false", func() {
Ω(checkMethod(ip)).Should(Equal(false))
})
})
when("http client return no error", func() {
var (
responseCode int
)
it.Before(func() {
check.GetStub = func(url string) (*http.Response, error) {
return &http.Response{
StatusCode: responseCode,
}, nil
}
})
when("response code match the status code:200", func() {
responseCode = 200
it("Should return true", func() {
Ω(checkMethod(ip)).Should(Equal(true))
})
})
when("response code not match the status code:200", func() {
responseCode = 400
it("Should return false", func() {
Ω(checkMethod(ip)).Should(Equal(false))
})
})
})
})
}