Refactor bosh dns unit test
@@ -19,11 +19,13 @@ import (
"code.cloudfoundry.org/quarks-operator/pkg/kube/util/boshdns"
)
-const boshDNSAddOn = `
+const aliasAddon = `
{
+ "name": "bosh-dns-aliases",
"jobs": [
{
"name": "bosh-dns-aliases",
+ "release": "bosh-dns-aliases",
"properties": {
"aliases": [
{
@@ -134,31 +136,30 @@ const boshDNSAddOn = `
]
}
]
- },
- "release": "bosh-dns-aliases"
}
- ],
- "name": "bosh-dns-aliases"
+ }
+ ]
}
`
-func loadAddOn() *manifest.AddOn {
+var _ = Describe("BOSHDomainNameService", func() {
+ Context("Apply", func() {
+ var (
+ client *cfakes.FakeClient
+ dns boshdns.DomainNameService
+ )
+
+ loadAddOn := func(addon string) *manifest.AddOn {
var addOn manifest.AddOn
- err := json.Unmarshal([]byte(boshDNSAddOn), &addOn)
+ err := json.Unmarshal([]byte(addon), &addOn)
if err != nil {
- // This should never happen, because boshDNSAddOn is a constant
+ // This should never happen, because test data is valid
panic("Loading yaml failed")
}
return &addOn
}
-var _ = Describe("BoshDomainNameService", func() {
- Context("Apply", func() {
- var (
- client *cfakes.FakeClient
- dns boshdns.DomainNameService
- )
-
+ When("BOSHDNS Addon has aliases", func() {
BeforeEach(func() {
igs := manifest.InstanceGroups{
&manifest.InstanceGroup{Name: "scheduler", AZs: []string{"az1", "az2"}},
@@ -166,7 +167,7 @@ var _ = Describe("BoshDomainNameService", func() {
&manifest.InstanceGroup{Name: "bits", AZs: []string{"az1", "az2"}},
}
var err error
- dns, err = boshdns.NewBoshDomainNameService(loadAddOn(), igs)
+ dns, err = boshdns.NewBoshDomainNameService(loadAddOn(aliasAddon), igs)
Expect(err).NotTo(HaveOccurred())
client = &cfakes.FakeClient{}
@@ -183,7 +184,7 @@ var _ = Describe("BoshDomainNameService", func() {
return nil
})
Expect(err).NotTo(HaveOccurred())
- Expect(client.CreateCallCount()).To(Equal(3))
+ Expect(client.CreateCallCount()).To(Equal(3)) // configmap, deployment, service
By("calling setOwner", func() {
Expect(counter).To(Equal(3))
@@ -223,3 +224,4 @@ template IN A uaa.service.cf.internal {
})
})
})
+})
