forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ping_retryable_test.go
77 lines (65 loc) · 2.33 KB
/
ping_retryable_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
77
package agentclient_test
import (
"errors"
"crypto/x509"
. "github.com/cloudfoundry/bosh-agent/agentclient"
fakeagentclient "github.com/cloudfoundry/bosh-agent/agentclient/fakes"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshretry "github.com/cloudfoundry/bosh-utils/retrystrategy"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("PingRetryable", func() {
Describe("Attempt", func() {
var (
fakeAgentClient *fakeagentclient.FakeAgentClient
pingRetryable boshretry.Retryable
)
BeforeEach(func() {
fakeAgentClient = &fakeagentclient.FakeAgentClient{}
pingRetryable = NewPingRetryable(fakeAgentClient)
})
It("tells the agent client to ping", func() {
isRetryable, err := pingRetryable.Attempt()
Expect(err).ToNot(HaveOccurred())
Expect(isRetryable).To(BeTrue())
Expect(fakeAgentClient.PingCallCount()).To(Equal(1))
})
Context("when pinging fails", func() {
BeforeEach(func() {
fakeAgentClient.PingReturns("", errors.New("fake-agent-client-ping-error"))
})
It("returns an error", func() {
isRetryable, err := pingRetryable.Attempt()
Expect(err).To(HaveOccurred())
Expect(isRetryable).To(BeTrue())
Expect(err.Error()).To(ContainSubstring("fake-agent-client-ping-error"))
})
})
Context("when failing with a certificate error", func() {
BeforeEach(func() {
fakeAgentClient.PingReturns("", errors.New("some error with x509: stuff"))
})
It("returns stops retrying and returns the error", func() {
isRetryable, err := pingRetryable.Attempt()
Expect(err).To(HaveOccurred())
Expect(isRetryable).To(BeFalse())
Expect(err.Error()).To(ContainSubstring("some error with x509: stuff"))
})
Context("when the certificate error is wrapped", func() {
BeforeEach(func() {
certError := x509.CertificateInvalidError{}
wrappedError := bosherr.WrapError(certError, "nope")
doubleWrappedError := bosherr.WrapError(wrappedError, "nope nope")
fakeAgentClient.PingReturns("", doubleWrappedError)
})
It("stops retrying and returns the error", func() {
isRetryable, err := pingRetryable.Attempt()
Expect(err).To(HaveOccurred())
Expect(isRetryable).To(BeFalse())
Expect(err.Error()).To(ContainSubstring("x509: certificate is not authorized to sign other certificates"))
})
})
})
})
})