本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.SetGlob方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.SetGlob方法的具體用法?Golang FakeFileSystem.SetGlob怎麽用?Golang FakeFileSystem.SetGlob使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.SetGlob方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
//.........這裏部分代碼省略.........
fs *fakesys.FakeFileSystem
platform boshplatform.Platform
boot Bootstrap
defaultNetworkResolver boshsettings.DefaultNetworkResolver
logger boshlog.Logger
dirProvider boshdirs.Provider
interfaceAddrsProvider *fakeip.FakeInterfaceAddressesProvider
)
writeNetworkDevice := func(iface string, macAddress string, isPhysical bool) string {
interfacePath := fmt.Sprintf("/sys/class/net/%s", iface)
fs.WriteFile(interfacePath, []byte{})
if isPhysical {
fs.WriteFile(fmt.Sprintf("/sys/class/net/%s/device", iface), []byte{})
}
fs.WriteFileString(fmt.Sprintf("/sys/class/net/%s/address", iface), fmt.Sprintf("%s\n", macAddress))
return interfacePath
}
stubInterfaces := func(interfaces [][]string) {
var interfacePaths []string
for _, iface := range interfaces {
interfaceName := iface[0]
interfaceMAC := iface[1]
interfaceType := iface[2]
isPhysical := interfaceType == "physical"
interfacePaths = append(interfacePaths, writeNetworkDevice(interfaceName, interfaceMAC, isPhysical))
}
fs.SetGlob("/sys/class/net/*", interfacePaths)
}
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner := fakesys.NewFakeCmdRunner()
dirProvider = boshdirs.NewProvider("/var/vcap/bosh")
linuxOptions := boshplatform.LinuxOptions{
CreatePartitionIfNoEphemeralDisk: true,
}
logger = boshlog.NewLogger(boshlog.LevelNone)
diskManager := fakedisk.NewFakeDiskManager()
diskManager.FakeMountsSearcher.SearchMountsMounts = []boshdisk.Mount{
{MountPoint: "/", PartitionPath: "rootfs"},
{MountPoint: "/", PartitionPath: "/dev/vda1"},
}
// for the GrowRootFS call to findRootDevicePath
runner.AddCmdResult(
"readlink -f /dev/vda1",
fakesys.FakeCmdResult{Stdout: "/dev/vda1"},
)
// for the createEphemeralPartitionsOnRootDevice call to findRootDevicePath
runner.AddCmdResult(
"readlink -f /dev/vda1",
fakesys.FakeCmdResult{Stdout: "/dev/vda1"},
)
diskManager.FakeRootDevicePartitioner.GetDeviceSizeInBytesSizes["/dev/vda"] = 1024 * 1024 * 1024
示例2:
Describe("DeleteFile()", func() {
var (
fakeFs *fakesys.FakeFileSystem
)
BeforeEach(func() {
fakeFs = fakesys.NewFakeFileSystem()
})
It("only deletes the files with the given prefix", func() {
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/delete/stuff/in/different_file_1.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.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(1))
})
It("only deletes the files in the given path", func() {
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",
})
示例3:
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() {
BeforeEach(func() {
err := fs.MkdirAll("fake-device-path-1", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())
示例4:
Expect(err).ToNot(HaveOccurred())
})
})
})
})
Describe("ChmodExecutables", func() {
var (
binGlob string
filePath string
)
BeforeEach(func() {
binGlob = "fake-glob/*"
filePath = "fake-glob/file"
fs.SetGlob("fake-glob/*", []string{filePath})
fs.WriteFileString(filePath, "content")
})
It("fetches the files", func() {
fileMode := fs.GetFileTestStat(filePath).FileMode
Expect(fileMode).To(Equal(os.FileMode(0)))
err := extractor.ChmodExecutables(binGlob)
Expect(err).ToNot(HaveOccurred())
fileMode = fs.GetFileTestStat(filePath).FileMode
Expect(fileMode).To(Equal(os.FileMode(0755)))
})
})
})
示例5: describeUbuntuNetManager
func describeUbuntuNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
addressBroadcaster *fakearp.FakeAddressBroadcaster
interfaceAddrsProvider *fakeip.FakeInterfaceAddressesProvider
netManager UbuntuNetManager
interfaceConfigurationCreator InterfaceConfigurationCreator
)
writeNetworkDevice := func(iface string, macAddress string, isPhysical bool) string {
interfacePath := fmt.Sprintf("/sys/class/net/%s", iface)
fs.WriteFile(interfacePath, []byte{})
if isPhysical {
fs.WriteFile(fmt.Sprintf("/sys/class/net/%s/device", iface), []byte{})
}
fs.WriteFileString(fmt.Sprintf("/sys/class/net/%s/address", iface), fmt.Sprintf("%s\n", macAddress))
return interfacePath
}
stubInterfacesWithVirtual := func(physicalInterfaces map[string]boshsettings.Network, virtualInterfaces []string) {
interfacePaths := []string{}
for iface, networkSettings := range physicalInterfaces {
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)
}
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
ipResolver = &fakeip.FakeResolver{}
logger := boshlog.NewLogger(boshlog.LevelNone)
interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger)
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
interfaceAddrsProvider = &fakeip.FakeInterfaceAddressesProvider{}
interfaceAddrsValidator := boship.NewInterfaceAddressesValidator(interfaceAddrsProvider)
dnsValidator := NewDNSValidator(fs)
netManager = NewUbuntuNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
interfaceAddrsValidator,
dnsValidator,
addressBroadcaster,
logger,
).(UbuntuNetManager)
})
Describe("ComputeNetworkConfig", func() {
Context("when there is one manual network and neither is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"manual": factory.Network{DNS: &[]string{"8.8.8.8"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
Context("when there is a vip network and a manual network and neither is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"vip": boshsettings.Network{Type: "vip"},
"manual": factory.Network{Type: "manual", DNS: &[]string{"8.8.8.8"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
Context("when there is a vip network and a manual network and the manual network is marked as default for DNS", func() {
It("should use the manual network for DNS", func() {
networks := boshsettings.Networks{
"vip": boshsettings.Network{Type: "vip"},
"manual": factory.Network{Type: "manual", DNS: &[]string{"8.8.8.8"}, Default: []string{"dns"}}.Build(),
}
stubInterfaces(networks)
_, _, dnsServers, err := netManager.ComputeNetworkConfig(networks)
Expect(err).ToNot(HaveOccurred())
Expect(dnsServers).To(Equal([]string{"8.8.8.8"}))
})
})
//.........這裏部分代碼省略.........
示例6: describeCentosNetManager
//.........這裏部分代碼省略.........
expectedNetworkConfigurationForDHCP = `DEVICE=ethdhcp
BOOTPROTO=dhcp
ONBOOT=yes
PEERDNS=yes
`
expectedDhclientConfiguration = `# Generated by bosh-agent
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
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;
prepend domain-name-servers 8.8.8.8, 9.9.9.9;
`
})
stubInterfacesWithVirtual := func(physicalInterfaces map[string]boshsettings.Network, virtualInterfaces []string) {
interfacePaths := []string{}
for iface, networkSettings := range physicalInterfaces {
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() {
示例7:
It("returns error", func() {
_, err := fileBundleCollection.Get(testBundle{Name: "fake-bundle-name"})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Missing bundle version"))
})
})
})
Describe("List", func() {
installPath := "/fake-collection-path/data/fake-collection-name"
enablePath := "/fake-collection-path/fake-collection-name"
It("returns list of installed bundles", func() {
fs.SetGlob(installPath+"/*/*", []string{
installPath + "/fake-bundle-1-name/fake-bundle-1-version-1",
installPath + "/fake-bundle-1-name/fake-bundle-1-version-2",
installPath + "/fake-bundle-2-name/fake-bundle-2-version-1",
})
bundles, err := fileBundleCollection.List()
Expect(err).ToNot(HaveOccurred())
expectedBundles := []Bundle{
NewFileBundle(
installPath+"/fake-bundle-1-name/fake-bundle-1-version-1",
enablePath+"/fake-bundle-1-name",
fs,
logger,
),
NewFileBundle(
installPath+"/fake-bundle-1-name/fake-bundle-1-version-2",
示例8:
Expect(udev.Triggered).To(Equal(true))
Expect(udev.Settled).To(Equal(true))
})
Context("when path exists", func() {
BeforeEach(func() {
err := fs.MkdirAll("/dev/fake-device-path", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())
err = fs.Symlink("/dev/fake-device-path", "/dev/intermediate/fake-device-path")
Expect(err).ToNot(HaveOccurred())
err = fs.Symlink("/dev/intermediate/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{"/dev/disk/by-id/virtio-fake-disk-id-include"})
})
It("returns fully resolved the path (not potentially relative symlink target)", func() {
path, timeout, err := pathResolver.GetRealDevicePath(diskSettings)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("/dev/fake-device-path"))
Expect(timeout).To(BeFalse())
})
})
Context("when disks with the same ID but different virtio prefixes exist ", func() {
BeforeEach(func() {
err := fs.MkdirAll("fake-device-path-1", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())
示例9:
BeforeEach(func() {
deviceID := "ab1b46b5-bf22-4332-bddd-12a05ea1a5fc"
id = strings.Replace(deviceID, "-", "", -1)
fs = fakesys.NewFakeFileSystem()
pathResolver = NewSCSIIDDevicePathResolver(500*time.Millisecond, fs, boshlog.NewLogger(boshlog.LevelNone))
diskSettings = boshsettings.DiskSettings{
DeviceID: deviceID,
}
hosts = []string{
"/sys/class/scsi_host/host0/scan",
"/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())
})
示例10:
var _ = Describe("SCSIVolumeIDDevicePathResolver", func() {
var (
fs *fakesys.FakeFileSystem
resolver DevicePathResolver
diskSettings boshsettings.DiskSettings
)
const sleepInterval = time.Millisecond * 1
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
resolver = NewSCSIVolumeIDDevicePathResolver(sleepInterval, fs)
fs.SetGlob("/sys/bus/scsi/devices/*:0:0:0/block/*", []string{
"/sys/bus/scsi/devices/0:0:0:0/block/sr0",
"/sys/bus/scsi/devices/6:0:0:0/block/sdd",
"/sys/bus/scsi/devices/fake-host-id:0:0:0/block/sda",
})
fs.SetGlob("/sys/bus/scsi/devices/fake-host-id:0:fake-disk-id:0/block/*", []string{
"/sys/bus/scsi/devices/fake-host-id:0:fake-disk-id:0/block/sdf",
})
diskSettings = boshsettings.DiskSettings{
VolumeID: "fake-disk-id",
}
})
Describe("GetRealDevicePath", func() {
It("rescans the devices attached to the root disks scsi controller", func() {
resolver.GetRealDevicePath(diskSettings)
示例11: init
//.........這裏部分代碼省略.........
// bundle installation did not happen before decompression
Expect(installedBeforeDecompression).To(BeFalse())
// make sure that bundle install happened after decompression
Expect(bundle.InstallSourcePath).To(Equal("/fake-tmp-dir/fake-path-in-archive"))
})
It("sets executable bit for the bin and config directories", func() {
var binDirStats, configDirStats *fakesys.FakeFileStats
compressor.DecompressFileToDirCallBack = func() {
fs.WriteFile("/fake-tmp-dir/fake-path-in-archive/bin/blarg", []byte{})
fs.WriteFile("/fake-tmp-dir/fake-path-in-archive/config/blarg.yml", []byte{})
}
bundle.InstallCallBack = func() {
binDirStats = fs.GetFileTestStat("/fake-tmp-dir/fake-path-in-archive/bin")
configDirStats = fs.GetFileTestStat("/fake-tmp-dir/fake-path-in-archive/config")
}
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(int(binDirStats.FileMode)).To(Equal(0755))
Expect(int(configDirStats.FileMode)).To(Equal(0755))
})
It("sets executable bit for files in bin", func() {
compressor.DecompressFileToDirCallBack = func() {
fs.WriteFile("/fake-tmp-dir/fake-path-in-archive/bin/test1", []byte{})
fs.WriteFile("/fake-tmp-dir/fake-path-in-archive/bin/test2", []byte{})
fs.WriteFile("/fake-tmp-dir/fake-path-in-archive/config/test", []byte{})
}
fs.SetGlob("/fake-tmp-dir/fake-path-in-archive/bin/*", []string{
"/fake-tmp-dir/fake-path-in-archive/bin/test1",
"/fake-tmp-dir/fake-path-in-archive/bin/test2",
})
var binTest1Stats, binTest2Stats, configTestStats *fakesys.FakeFileStats
bundle.InstallCallBack = func() {
binTest1Stats = fs.GetFileTestStat("/fake-tmp-dir/fake-path-in-archive/bin/test1")
binTest2Stats = fs.GetFileTestStat("/fake-tmp-dir/fake-path-in-archive/bin/test2")
configTestStats = fs.GetFileTestStat("/fake-tmp-dir/fake-path-in-archive/config/test")
}
err := act()
Expect(err).ToNot(HaveOccurred())
// bin files are executable
Expect(int(binTest1Stats.FileMode)).To(Equal(0755))
Expect(int(binTest2Stats.FileMode)).To(Equal(0755))
// non-bin files are not made executable
Expect(int(configTestStats.FileMode)).ToNot(Equal(0755))
})
It("sets 644 permissions for files in config", func() {
compressor.DecompressFileToDirCallBack = func() {
fs.WriteFile("/fake-tmp-dir/fake-path-in-archive/config/config1", []byte{})
fs.WriteFile("/fake-tmp-dir/fake-path-in-archive/config/config2", []byte{})
}
fs.SetGlob("/fake-tmp-dir/fake-path-in-archive/config/*", []string{
"/fake-tmp-dir/fake-path-in-archive/config/config1",
"/fake-tmp-dir/fake-path-in-archive/config/config2",
示例12:
fs = fakesys.NewFakeFileSystem()
pathResolver = NewSCSILunDevicePathResolver(500*time.Millisecond, fs, boshlog.NewLogger(boshlog.LevelNone))
diskSettings = boshsettings.DiskSettings{
Lun: lun,
HostDeviceID: "fake-host-device-id",
}
hosts = []string{
"/sys/class/scsi_host/host0/scan",
"/sys/class/scsi_host/host1/scan",
"/sys/class/scsi_host/host2/scan",
"/sys/class/scsi_host/host3/scan",
"/sys/class/scsi_host/host4/scan",
"/sys/class/scsi_host/host5/scan",
}
fs.SetGlob("/sys/class/scsi_host/host*/scan", hosts)
fs.SetGlob("/sys/bus/scsi/devices/*:*:*:"+lun+"/block/*", []string{
"/sys/bus/scsi/devices/2:0:0:0/block/sda",
"/sys/bus/scsi/devices/3:0:1:0/block/sdb",
"/sys/bus/scsi/devices/5:0:0:" + lun + "/block/sdc",
})
fs.SetGlob("/sys/bus/vmbus/devices/*/device_id", []string{
"/sys/bus/vmbus/devices/fake-vmbus-device/device_id",
"/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() {
示例13:
It("returns error", func() {
_, err := fileBundleCollection.Get(testBundle{Name: "fake-bundle-name"})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Missing bundle version"))
})
})
})
Describe("List", func() {
installPath := `C:\fake-collection-path\data\fake-collection-name`
enablePath := `C:\fake-collection-path\fake-collection-name`
It("returns list of installed bundles for windows style paths", func() {
fs.SetGlob(cleanPath(installPath+`\*\*`), []string{
installPath + `\fake-bundle-1-name\fake-bundle-1-version-1`,
installPath + `\fake-bundle-1-name\fake-bundle-1-version-2`,
installPath + `\fake-bundle-1-name\fake-bundle-2-version-1`,
})
bundles, err := fileBundleCollection.List()
Expect(err).ToNot(HaveOccurred())
expectedBundles := []Bundle{
NewFileBundle(
cleanPath(installPath+`\fake-bundle-1-name\fake-bundle-1-version-1`),
cleanPath(enablePath+`\fake-bundle-1-name`),
fs,
logger,
),
NewFileBundle(
cleanPath(installPath+`\fake-bundle-1-name\fake-bundle-1-version-2`),