本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.SymlinkError方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.SymlinkError方法的具體用法?Golang FakeFileSystem.SymlinkError怎麽用?Golang FakeFileSystem.SymlinkError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.SymlinkError方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: describeCentosNetManager
//.........這裏部分代碼省略.........
send host-name "<hostname>";
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
`))
dhcpConfigSymlink := fs.GetFileTestStat("/etc/dhcp/dhclient-ethdhcp.conf")
Expect(dhcpConfigSymlink).ToNot(BeNil())
Expect(dhcpConfigSymlink.SymlinkTarget).To(Equal("/etc/dhcp/dhclient.conf"))
})
It("returns an error if it can't write a dhcp configuration", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic": staticNetwork,
})
fs.WriteFileErrors["/etc/dhcp/dhclient.conf"] = errors.New("dhclient.conf-write-error")
err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("dhclient.conf-write-error"))
})
It("returns an error if it can't symlink a dhcp configuration", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic": staticNetwork,
})
fs.SymlinkError = errors.New("dhclient-ethdhcp.conf-symlink-error")
err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("dhclient-ethdhcp.conf-symlink-error"))
})
It("doesn't write a dhcp configuration if there are no dhcp networks", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethstatic": staticNetwork,
})
err := netManager.SetupNetworking(boshsettings.Networks{"static-network": staticNetwork}, nil)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient-ethdhcp.conf")
Expect(dhcpConfig).To(BeNil())
})
It("restarts the networks if any ifconfig file changes", func() {
changingStaticNetwork := boshsettings.Network{
Type: "manual",
IP: "1.2.3.5",
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
Mac: "ethstatict-that-changes",
}
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic-that-changes": changingStaticNetwork,
"ethstatic": staticNetwork,
})
示例2:
It("returns error", func() {
_, _, err := fileBundle.Install(sourcePath)
Expect(err).NotTo(HaveOccurred())
fs.MkdirAllError = errors.New("fake-mkdirall-error")
_, _, err = fileBundle.Enable()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-mkdirall-error"))
})
})
Context("when bundle cannot be enabled", func() {
It("returns error", func() {
_, _, err := fileBundle.Install(sourcePath)
Expect(err).NotTo(HaveOccurred())
fs.SymlinkError = errors.New("fake-symlink-error")
_, _, err = fileBundle.Enable()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-symlink-error"))
})
})
})
Describe("Disable", func() {
It("is idempotent", func() {
err := fileBundle.Disable()
Expect(err).NotTo(HaveOccurred())
err = fileBundle.Disable()
Expect(err).NotTo(HaveOccurred())
示例3: describeUbuntuNetManager
//.........這裏部分代碼省略.........
err = fs.WriteFileString("/etc/resolv.conf", "fake-content")
Expect(err).ToNot(HaveOccurred())
})
It("copies /etc/resolv.conf to .../resolv.conf.d/base", func() {
err := netManager.SetupNetworking(networks, nil)
Expect(err).ToNot(HaveOccurred())
contents, err := fs.ReadFile("/etc/resolvconf/resolv.conf.d/base")
Expect(err).ToNot(HaveOccurred())
Expect(string(contents)).To(Equal("fake-content"))
})
Context("when copying fails", func() {
It("fails reporting the error", func() {
fs.CopyFileError = errors.New("fake-copy-error")
err := netManager.SetupNetworking(networks, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Copying /etc/resolv.conf for backwards compat"))
})
})
})
})
It("forces /etc/resolv.conf to be a symlink", func() {
err := netManager.SetupNetworking(networks, nil)
Expect(err).ToNot(HaveOccurred())
Expect(fs.ReadLink("/etc/resolv.conf")).To(Equal("/run/resolvconf/resolv.conf"))
})
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))
})