forked from AbelHu/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry_endpoint_resolver_test.go
66 lines (56 loc) · 2.12 KB
/
registry_endpoint_resolver_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
package infrastructure_test
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/infrastructure"
fakeinf "github.com/cloudfoundry/bosh-agent/infrastructure/fakes"
)
var _ = Describe("RegistryEndpointResolver", func() {
Describe("LookupHost", func() {
var (
dnsServers []string
registryEndpointResolver DNSResolver
delegate *fakeinf.FakeDNSResolver
)
BeforeEach(func() {
dnsServers = []string{"fake-dns-server-ip"}
delegate = &fakeinf.FakeDNSResolver{}
registryEndpointResolver = NewRegistryEndpointResolver(delegate)
})
Context("when registry endpoint is successfully resolved", func() {
BeforeEach(func() {
delegate.RegisterRecord(fakeinf.FakeDNSRecord{
DNSServers: dnsServers,
Host: "fake-registry.com",
IP: "fake-registry-ip",
})
})
Context("when registry endpoint has a port", func() {
It("returns the successfully resolved registry endpoint with port", func() {
resolvedEndpoint, err := registryEndpointResolver.LookupHost(dnsServers, "http://fake-registry.com:8877")
Expect(err).ToNot(HaveOccurred())
Expect(resolvedEndpoint).To(Equal("http://fake-registry-ip:8877"))
})
})
Context("when registry endpoint does not have a port", func() {
It("returns the successfully resolved registry endpoint", func() {
resolvedEndpoint, err := registryEndpointResolver.LookupHost(dnsServers, "http://fake-registry.com")
Expect(err).ToNot(HaveOccurred())
Expect(resolvedEndpoint).To(Equal("http://fake-registry-ip"))
})
})
})
Context("when registry endpoint is not successfully resolved", func() {
BeforeEach(func() {
delegate.LookupHostErr = errors.New("fake-lookup-host-err")
})
It("returns error because it failed to resolve registry endpoint", func() {
resolvedEndpoint, err := registryEndpointResolver.LookupHost(dnsServers, "http://fake-registry.com")
Expect(resolvedEndpoint).To(BeEmpty())
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-lookup-host-err"))
})
})
})
})