Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lnguyen committed Mar 25, 2024
1 parent e9bd9f4 commit ed63af7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 68 deletions.
2 changes: 1 addition & 1 deletion platform/net/dnsresolver/dns_systemd_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (d *systemdResolver) Validate(dnsServers []string) error {
}
}
}
return bosherr.WrapError(err, "None of the DNS servers that were specified in the manifest were found in /etc/resolv.conf.")
return bosherr.WrapError(err, "None of the DNS servers that were specified in the manifest were found in /etc/systemd/resolved.conf.d/10-bosh.conf.")
}

func (d *systemdResolver) SetupDNS(dnsServers []string) error {
Expand Down
2 changes: 2 additions & 0 deletions platform/net/dnsresolver/dns_systemd_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var _ = Describe("systemdConfResolver", func() {
Context("when /etc/systemd/resolved.conf.d/10-bosh.conf contains at least one dns server", func() {
BeforeEach(func() {
err := fs.WriteFileString("/etc/systemd/resolved.conf.d/10-bosh.conf", `
[Resolve]
DNS=8.8.8.8 9.9.9.9`)
Expect(err).NotTo(HaveOccurred())
})
Expand Down Expand Up @@ -65,6 +66,7 @@ var _ = Describe("systemdConfResolver", func() {
Expect(resolvConfBase).ToNot(BeNil())

expectedResolvConfBase := `# Generated by bosh-agent
[Resolve]
DNS=8.8.8.8 9.9.9.9`
Expect(resolvConfBase.StringContents()).To(ContainSubstring(expectedResolvConfBase))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"systemctl", "restart", "systemd-resolved"}))
Expand Down
67 changes: 0 additions & 67 deletions platform/net/ubuntu_net_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package net_test

import (
"errors"
"path/filepath"
"strings"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -237,7 +236,6 @@ var _ = Describe("ubuntuNetManager", func() {
dhcpNetwork boshsettings.Network
staticNetwork boshsettings.Network
expectedNetworkConfigurationForStaticAndDhcp string
expectedResolvConfHead string
)

BeforeEach(func() {
Expand All @@ -258,11 +256,6 @@ var _ = Describe("ubuntuNetManager", func() {
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("ethstatic", "1.2.3.4"),
}
err := fs.WriteFileString("/etc/resolv.conf", `
nameserver 8.8.8.8
nameserver 9.9.9.9
`)
Expect(err).NotTo(HaveOccurred())
expectedNetworkConfigurationForStaticAndDhcp = `# Generated by bosh-agent
auto lo
iface lo inet loopback
Expand Down Expand Up @@ -294,66 +287,6 @@ dns-nameservers 8.8.8.8 9.9.9.9`
Expect(networks.IsPreconfigured()).To(BeTrue())
})

It("forces /etc/resolv.conf to be a symlink", func() {
err := netManager.SetupNetworking(networks, "", nil)
Expect(err).ToNot(HaveOccurred())
linkContents, err := fs.Readlink("/etc/resolv.conf")
Expect(err).ToNot(HaveOccurred())

expectedContents, err := filepath.Abs("/run/resolvconf/resolv.conf")
Expect(err).ToNot(HaveOccurred())
Expect(linkContents).To(Equal(expectedContents))
})

Context("when symlink command fails", func() {
BeforeEach(func() {
fs.SymlinkError = errors.New("fake-symlink-error")
})

It("fails reporting error", func() {
err := netManager.SetupNetworking(networks, "", nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Setting up /etc/resolv.conf symlink"))
})
})

It("writes dns servers in /etc/resolvconf/resolv.conf.d/base", func() {
dhcpNetwork.Preconfigured = true
staticNetwork.Preconfigured = true
networks := boshsettings.Networks{
"first": dhcpNetwork,
"second": staticNetwork,
}

Expect(networks.IsPreconfigured()).To(BeTrue())

err := netManager.SetupNetworking(networks, "", nil)
Expect(err).ToNot(HaveOccurred())

resolvConfHead := fs.GetFileTestStat("/etc/resolvconf/resolv.conf.d/base")
Expect(resolvConfHead).ToNot(BeNil())

expectedResolvConfHead = `# Generated by bosh-agent
nameserver 8.8.8.8
nameserver 9.9.9.9
`
Expect(resolvConfHead.StringContents()).To(Equal(expectedResolvConfHead))
})

It("run resolvconf -u to update resolv.conf", func() {
dhcpNetwork.Preconfigured = true
staticNetwork.Preconfigured = true
networks := boshsettings.Networks{
"first": dhcpNetwork,
"second": staticNetwork,
}

err := netManager.SetupNetworking(networks, "", nil)
Expect(err).ToNot(HaveOccurred())

Expect(len(cmdRunner.RunCommands)).To(Equal(1))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"resolvconf", "-u"}))
})
})

It("configures gateway, broadcast and dns for default network only", func() {
Expand Down

0 comments on commit ed63af7

Please sign in to comment.