本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.GlobErr方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.GlobErr方法的具體用法?Golang FakeFileSystem.GlobErr怎麽用?Golang FakeFileSystem.GlobErr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.GlobErr方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
fakeFs.WriteFileString("/path/to/delete/stuff/in/delete_me_1.foo", "goodbye")
fakeFs.WriteFileString("/path/to/delete/stuff/in/delete_me_2.foo", "goodbye")
fakeFs.WriteFileString("/path/to/other/things/in/delete_me_3.foo", "goodbye")
fakeFs.SetGlob("/path/to/delete/stuff/in/delete_me_*", []string{
"/path/to/delete/stuff/in/delete_me_1.foo",
"/path/to/delete/stuff/in/delete_me_2.foo",
})
count, err := cert.DeleteFiles(fakeFs, "/path/to/delete/stuff/in/", "delete_me_")
Expect(err).ToNot(HaveOccurred())
Expect(count).To(Equal(2))
Expect(countFiles(fakeFs, "/path/to/delete/stuff/in/")).To(Equal(0))
Expect(countFiles(fakeFs, "/path/to/other/things/in/")).To(Equal(1))
})
It("returns an error when glob fails", func() {
fakeFs.GlobErr = errors.New("couldn't walk")
fakeFs.WriteFileString("/path/to/delete/stuff/in/delete_me_1.foo", "goodbye")
fakeFs.WriteFileString("/path/to/delete/stuff/in/delete_me_2.bar", "goodbye")
count, err := cert.DeleteFiles(fakeFs, "/path/to/delete/stuff/in/", "delete_me_")
Expect(err).To(HaveOccurred())
Expect(count).To(Equal(0))
})
It("returns an error when RemoveAll() fails", func() {
fakeFs.RemoveAllError = errors.New("couldn't delete")
fakeFs.WriteFileString("/path/to/delete/stuff/in/delete_me_1.foo", "goodbye")
fakeFs.WriteFileString("/path/to/delete/stuff/in/delete_me_2.bar", "goodbye")
fakeFs.SetGlob("/path/to/delete/stuff/in/delete_me_*", []string{
"/path/to/delete/stuff/in/delete_me_1.foo",
"/path/to/delete/stuff/in/delete_me_2.bar",
})
示例2: describeUbuntuNetManager
//.........這裏部分代碼省略.........
staticNetworkWithoutDNS := boshsettings.Network{
Type: "manual",
IP: "1.2.3.4",
Default: []string{"gateway"},
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
Mac: "fake-static-mac-address",
}
stubInterfaces(map[string]boshsettings.Network{
"ethstatic": staticNetworkWithoutDNS,
})
err := netManager.SetupNetworking(boshsettings.Networks{"static-network": staticNetworkWithoutDNS}, nil)
Expect(err).ToNot(HaveOccurred())
networkConfig := fs.GetFileTestStat("/etc/network/interfaces")
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(`# Generated by bosh-agent
auto lo
iface lo inet loopback
auto ethstatic
iface ethstatic inet static
address 1.2.3.4
network 1.2.3.0
netmask 255.255.255.0
broadcast 1.2.3.255
gateway 3.4.5.6
`))
})
It("returns errors from glob /sys/class/net/", func() {
fs.GlobErr = errors.New("fs-glob-error")
err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fs-glob-error"))
})
It("returns errors from writing the network configuration", func() {
stubInterfaces(map[string]boshsettings.Network{
"dhcp": dhcpNetwork,
"static": staticNetwork,
})
fs.WriteFileError = errors.New("fs-write-file-error")
err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fs-write-file-error"))
})
It("returns errors when it can't creating network interface configurations", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic": staticNetwork,
})
staticNetwork.Netmask = "not an ip" //will cause InterfaceConfigurationCreator to fail
err := netManager.SetupNetworking(boshsettings.Networks{"static-network": staticNetwork}, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Creating interface configurations"))
})
It("writes a dhcp configuration if there are dhcp networks", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic": staticNetwork,
})
示例3: describeCentosNetManager
//.........這裏部分代碼省略.........
interfacePaths = append(interfacePaths, writeNetworkDevice(iface, networkSettings.Mac, true))
}
for _, iface := range virtualInterfaces {
interfacePaths = append(interfacePaths, writeNetworkDevice(iface, "virtual", false))
}
fs.SetGlob("/sys/class/net/*", interfacePaths)
}
stubInterfaces := func(physicalInterfaces map[string]boshsettings.Network) {
stubInterfacesWithVirtual(physicalInterfaces, nil)
}
It("writes a network script for static and dynamic interfaces", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic": staticNetwork,
})
err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil)
Expect(err).ToNot(HaveOccurred())
staticConfig := fs.GetFileTestStat("/etc/sysconfig/network-scripts/ifcfg-ethstatic")
Expect(staticConfig).ToNot(BeNil())
Expect(staticConfig.StringContents()).To(Equal(expectedNetworkConfigurationForStatic))
dhcpConfig := fs.GetFileTestStat("/etc/sysconfig/network-scripts/ifcfg-ethdhcp")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedNetworkConfigurationForDHCP))
})
It("returns errors from glob /sys/class/net/", func() {
fs.GlobErr = errors.New("fs-glob-error")
err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fs-glob-error"))
})
It("returns errors from writing the network configuration", func() {
stubInterfaces(map[string]boshsettings.Network{
"dhcp": dhcpNetwork,
"static": staticNetwork,
})
fs.WriteFileError = errors.New("fs-write-file-error")
err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fs-write-file-error"))
})
It("returns errors when it can't create network interface configurations", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethstatic": staticNetwork,
})
staticNetwork.Netmask = "not an ip" //will cause InterfaceConfigurationCreator to fail
err := netManager.SetupNetworking(boshsettings.Networks{"static-network": staticNetwork}, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Creating interface configurations"))
})
It("wrtites a dhcp configuration if there are dhcp networks", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic": staticNetwork,
})
示例4:
fs,
logger,
),
NewFileBundle(
installPath+"/fake-bundle-2-name/fake-bundle-2-version-1",
enablePath+"/fake-bundle-2-name",
fs,
logger,
),
}
Expect(bundles).To(Equal(expectedBundles))
})
It("returns error when glob fails to execute", func() {
fs.GlobErr = errors.New("fake-glob-error")
_, err := fileBundleCollection.List()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-glob-error"))
})
It("returns error when bundle cannot be built from matched path", func() {
invalidPaths := []string{
"",
"/",
"before-slash/",
"/after-slash",
"no-slash",
}