本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.Symlink方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.Symlink方法的具體用法?Golang FakeFileSystem.Symlink怎麽用?Golang FakeFileSystem.Symlink使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.Symlink方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
pathResolver = NewIDDevicePathResolver(500*time.Millisecond, udev, fs)
})
Describe("GetRealDevicePath", func() {
It("refreshes udev", func() {
pathResolver.GetRealDevicePath(diskSettings)
Expect(udev.Triggered).To(Equal(true))
Expect(udev.Settled).To(Equal(true))
})
Context("when path exists", func() {
BeforeEach(func() {
err := fs.MkdirAll("fake-device-path", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())
err = fs.Symlink("fake-device-path", "/dev/disk/by-id/virtio-fake-disk-id-include")
Expect(err).ToNot(HaveOccurred())
fs.SetGlob("/dev/disk/by-id/*fake-disk-id-include", []string{"fake-device-path"})
})
It("returns the path", func() {
path, timeout, err := pathResolver.GetRealDevicePath(diskSettings)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("fake-device-path"))
Expect(timeout).To(BeFalse())
})
})
Context("when disks with the same ID but different virtio prefixes exist ", func() {
示例2:
"/sys/class/scsi_host/host1/scan",
"/sys/class/scsi_host/host2/scan",
}
fs.SetGlob("/sys/class/scsi_host/host*/scan", hosts)
fs.SetGlob("/dev/disk/by-id/*"+id, []string{
"/dev/disk/by-id/scsi-3" + id,
})
})
Describe("GetRealDevicePath", func() {
Context("when path exists", func() {
BeforeEach(func() {
err := fs.MkdirAll("fake-device-path", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())
err = fs.Symlink("fake-device-path", "/dev/disk/by-id/scsi-3"+id)
Expect(err).ToNot(HaveOccurred())
})
It("returns the path", func() {
path, timeout, err := pathResolver.GetRealDevicePath(diskSettings)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("fake-device-path"))
Expect(timeout).To(BeFalse())
for _, host := range hosts {
str, _ := fs.ReadFileString(host)
Expect(str).To(Equal("- - -"))
}
})
示例3:
"/sys/bus/vmbus/devices/vmbus_0_12/device_id",
"/sys/bus/vmbus/devices/vmbus_12/device_id",
})
})
Describe("GetRealDevicePath", func() {
Context("when path exists", func() {
BeforeEach(func() {
deviceIDPath := "/sys/bus/vmbus/devices/fake-vmbus-device/device_id"
err := fs.WriteFileString(deviceIDPath, "fake-host-device-id")
Expect(err).ToNot(HaveOccurred())
err = fs.MkdirAll("fake-root/fake-vmbus-device/fake-base", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())
err = fs.Symlink("fake-root/fake-vmbus-device/fake-base", "/sys/class/block/sdc")
Expect(err).ToNot(HaveOccurred())
err = fs.MkdirAll("/dev/sdc", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())
})
It("returns the real path", func() {
path, timeout, err := pathResolver.GetRealDevicePath(diskSettings)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("/dev/sdc"))
Expect(timeout).To(BeFalse())
for _, host := range hosts {
str, _ := fs.ReadFileString(host)
示例4: describeUbuntuNetManager
//.........這裏部分代碼省略.........
Context("when writing to ../resolv.conf.d/base fails", func() {
It("fails reporting the error", func() {
fs.WriteFileError = errors.New("fake-write-file-error")
err := netManager.SetupNetworking(networks, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Writing to /etc/resolvconf/resolv.conf.d/base"))
})
})
})
Context("when no DNS servers are configured", func() {
BeforeEach(func() {
dhcpNetwork.DNS = []string{}
networks = boshsettings.Networks{
"first": dhcpNetwork,
"second": staticNetwork,
}
})
Context("when could not read link /etc/resolv.conf", func() {
It("fails reporting error", func() {
fs.ReadLinkError = errors.New("fake-read-link-error")
err := netManager.SetupNetworking(networks, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Reading /etc/resolv.conf symlink"))
})
})
Context("when /etc/resolv.conf is no symlink", func() {
BeforeEach(func() {
err := fs.Symlink("/etc/resolv.conf", "/etc/resolv.conf")
Expect(err).ToNot(HaveOccurred())
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"))
})
示例5:
}
})
Describe("GetRealDevicePath", func() {
It("refreshes udev", func() {
pathResolver.GetRealDevicePath(diskSettings)
Expect(udev.Triggered).To(Equal(true))
Expect(udev.Settled).To(Equal(true))
})
Context("when path exists", func() {
BeforeEach(func() {
err := fs.MkdirAll("fake-device-path", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())
err = fs.Symlink("fake-device-path", "/dev/disk/by-id/virtio-fake-disk-id-include")
Expect(err).ToNot(HaveOccurred())
})
It("returns the path ", func() {
path, timeout, err := pathResolver.GetRealDevicePath(diskSettings)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("fake-device-path"))
Expect(timeout).To(BeFalse())
})
})
Context("when path does not exist", func() {
BeforeEach(func() {
err := fs.Symlink("fake-device-path", "/dev/disk/by-id/virtio-fake-disk-id-include")