本文整理匯總了Golang中bosh/system/fakes.FakeFileSystem.SetGlob方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.SetGlob方法的具體用法?Golang FakeFileSystem.SetGlob怎麽用?Golang FakeFileSystem.SetGlob使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bosh/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.SetGlob方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
//.........這裏部分代碼省略.........
Expect(tmpDirExistsBeforeInstall).To(BeTrue())
// tmp dir is cleaned up after install
Expect(fs.FileExists(fs.TempDirDir)).To(BeFalse())
})
It("returns error when temporary directory creation fails", func() {
fs.TempDirError = errors.New("fake-filesystem-tempdir-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-filesystem-tempdir-error"))
})
It("returns error when decompressing job template fails", func() {
compressor.DecompressFileToDirErr = errors.New("fake-decompress-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-decompress-error"))
})
It("returns error when getting the list of bin files fails", func() {
fs.GlobErr = errors.New("fake-glob-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-glob-error"))
})
It("returns error when changing permissions on bin files fails", func() {
fs.TempDirDir = "/fake-tmp-dir"
fs.SetGlob("/fake-tmp-dir/fake-path-in-archive/bin/*", []string{
"/fake-tmp-dir/fake-path-in-archive/bin/test",
})
fs.ChmodErr = errors.New("fake-chmod-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-chmod-error"))
})
It("installs bundle from decompressed tmp path of a job template", func() {
fs.TempDirDir = "/fake-tmp-dir"
var installedBeforeDecompression bool
compressor.DecompressFileToDirCallBack = func() {
installedBeforeDecompression = bundle.Installed
}
err := act()
Expect(err).ToNot(HaveOccurred())
// 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 files in bin", func() {
fs.TempDirDir = "/fake-tmp-dir"
示例2: init
//.........這裏部分代碼省略.........
})
Context("when dhcp was previously configured with different configuration", func() {
BeforeEach(func() {
fs.WriteFileString("/etc/dhcp/dhclient.conf", "fake-other-configuration")
})
ItUpdatesDhcpConfig()
ItRestartsDhcp()
})
Context("when dhcp was previously configured with the same configuration", func() {
BeforeEach(func() {
fs.WriteFileString("/etc/dhcp/dhclient.conf", expectedUbuntuDHCPConfig)
})
ItUpdatesDhcpConfig()
ItDoesNotRestartDhcp()
})
})
})
Describe("SetupManualNetworking", func() {
var errCh chan error
BeforeEach(func() {
errCh = make(chan error)
})
BeforeEach(func() {
// For mac addr to interface resolution
fs.WriteFile("/sys/class/net/eth0", []byte{})
fs.WriteFileString("/sys/class/net/eth0/address", "22:00:0a:1f:ac:2a\n")
fs.SetGlob("/sys/class/net/*", []string{"/sys/class/net/eth0"})
})
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns", "gateway"},
IP: "192.168.195.6",
Netmask: "255.255.255.0",
Gateway: "192.168.195.1",
Mac: "22:00:0a:1f:ac:2a",
DNS: []string{"10.80.130.2", "10.80.130.1"},
},
}
Context("when manual networking was not previously configured", func() {
It("writes /etc/network/interfaces", func() {
err := netManager.SetupManualNetworking(networks, nil)
Expect(err).ToNot(HaveOccurred())
networkConfig := fs.GetFileTestStat("/etc/network/interfaces")
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(expectedUbuntuNetworkInterfaces))
})
It("restarts networking", func() {
err := netManager.SetupManualNetworking(networks, errCh)
Expect(err).ToNot(HaveOccurred())
<-errCh // wait for all arpings
Expect(len(cmdRunner.RunCommands) >= 2).To(BeTrue())
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"service", "network-interface", "stop", "INTERFACE=eth0"}))
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"service", "network-interface", "start", "INTERFACE=eth0"}))
示例3: init
//.........這裏部分代碼省略.........
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"pkill", "dhclient3"}))
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"/etc/init.d/networking", "restart"}))
})
})
Context("when dhcp was previously configured with the same configuration", func() {
BeforeEach(func() {
fs.WriteFileString("/etc/dhcp3/dhclient.conf", expectedUbuntuDHCPConfig)
})
It("does not restart dhclient", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp3/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedUbuntuDHCPConfig))
})
It("does not restart dhclient", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(0))
})
})
})
Describe("SetupManualNetworking", func() {
BeforeEach(func() {
// For mac addr to interface resolution
fs.WriteFile("/sys/class/net/eth0", []byte{})
fs.WriteFileString("/sys/class/net/eth0/address", "22:00:0a:1f:ac:2a\n")
fs.SetGlob("/sys/class/net/*", []string{"/sys/class/net/eth0"})
})
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns", "gateway"},
IP: "192.168.195.6",
Netmask: "255.255.255.0",
Gateway: "192.168.195.1",
Mac: "22:00:0a:1f:ac:2a",
DNS: []string{"10.80.130.2", "10.80.130.1"},
},
}
Context("when manual networking was not previously configured", func() {
It("writes /etc/network/interfaces", func() {
err := platform.SetupManualNetworking(networks)
Expect(err).ToNot(HaveOccurred())
networkConfig := fs.GetFileTestStat("/etc/network/interfaces")
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(expectedUbuntuNetworkInterfaces))
})
It("restarts networking", func() {
err := platform.SetupManualNetworking(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands) >= 2).To(BeTrue())
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"service", "network-interface", "stop", "INTERFACE=eth0"}))
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"service", "network-interface", "start", "INTERFACE=eth0"}))
})
示例4:
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
diskManager = fakedisk.NewFakeDiskManager()
dirProvider = boshdirs.NewDirectoriesProvider("/fake-dir")
diskWaitTimeout = 1 * time.Millisecond
cdutil = fakecd.NewFakeCdUtil()
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
copier = boshcmd.NewCpCopier(cmdRunner, fs, logger)
vitalsService = boshvitals.NewService(collector, dirProvider)
netManager = &fakenet.FakeNetManager{}
devicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
options = LinuxOptions{}
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",
})
})
JustBeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
platform = NewLinuxPlatform(
fs,
cmdRunner,
collector,
示例5: init
//.........這裏部分代碼省略.........
dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedCentosDHCPConfig))
})
It("restarts network", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(1))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"service", "network", "restart"}))
})
})
Context("when dhcp was previously configured with same configuration", func() {
BeforeEach(func() {
fs.WriteFileString("/etc/dhcp/dhclient.conf", expectedCentosDHCPConfig)
})
It("keeps dhcp configuration", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedCentosDHCPConfig))
})
It("does not restart network", func() {
err := platform.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(0))
})
})
})
Describe("SetupManualNetworking", func() {
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns", "gateway"},
IP: "192.168.195.6",
Netmask: "255.255.255.0",
Gateway: "192.168.195.1",
Mac: "22:00:0a:1f:ac:2a",
DNS: []string{"10.80.130.2", "10.80.130.1"},
},
}
BeforeEach(func() {
fs.WriteFile("/sys/class/net/eth0", []byte{})
fs.WriteFileString("/sys/class/net/eth0/address", "22:00:0a:1f:ac:2a\n")
fs.SetGlob("/sys/class/net/*", []string{"/sys/class/net/eth0"})
})
It("sets up centos expected ifconfig", func() {
err := platform.SetupManualNetworking(networks)
Expect(err).ToNot(HaveOccurred())
networkConfig := fs.GetFileTestStat("/etc/sysconfig/network-scripts/ifcfg-eth0")
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(expectedCentosIfcfg))
})
It("sets up centos /etc/resolv.conf", func() {
err := platform.SetupManualNetworking(networks)
Expect(err).ToNot(HaveOccurred())
resolvConf := fs.GetFileTestStat("/etc/resolv.conf")
Expect(resolvConf).ToNot(BeNil())
Expect(resolvConf.StringContents()).To(Equal(expectedCentosResolvConf))
})
It("restarts networking", func() {
err := platform.SetupManualNetworking(networks)
Expect(err).ToNot(HaveOccurred())
fs.GetFileTestStat("/etc/sysconfig/network-scripts/ifcfg-eth0")
fs.GetFileTestStat("/etc/resolv.conf")
time.Sleep(100 * time.Millisecond)
Expect(len(cmdRunner.RunCommands)).To(Equal(7))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"service", "network", "restart"}))
})
It("runs arping commands", func() {
err := platform.SetupManualNetworking(networks)
Expect(err).ToNot(HaveOccurred())
fs.GetFileTestStat("/etc/sysconfig/network-scripts/ifcfg-eth0")
fs.GetFileTestStat("/etc/resolv.conf")
time.Sleep(100 * time.Millisecond)
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"arping", "-c", "1", "-U", "-I", "eth0", "192.168.195.6"}))
Expect(cmdRunner.RunCommands[6]).To(Equal([]string{"arping", "-c", "1", "-U", "-I", "eth0", "192.168.195.6"}))
})
})
})
}
示例6:
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",
示例7:
})
ItBroadcastsMACAddresses()
})
})
Describe("SetupManualNetworking", func() {
var errCh chan error
BeforeEach(func() {
errCh = make(chan error)
})
BeforeEach(func() {
fs.WriteFileString("/sys/class/net/eth0/address", "22:00:0a:1f:ac:2a\n")
fs.SetGlob("/sys/class/net/*", []string{"/sys/class/net/eth0"})
})
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns", "gateway"},
IP: "192.168.195.6",
Netmask: "255.255.255.0",
Gateway: "192.168.195.1",
Mac: "22:00:0a:1f:ac:2a",
DNS: []string{"10.80.130.2", "10.80.130.1"},
},
}
It("sets up centos expected ifconfig", func() {
err := netManager.SetupManualNetworking(networks, nil)
示例8: init
//.........這裏部分代碼省略.........
})
ItBroadcastsMACAddresses()
})
Context("when dhcp was previously configured with same configuration", func() {
BeforeEach(func() {
fs.WriteFileString("/etc/dhcp/dhclient.conf", expectedCentosDHCPConfig)
})
It("keeps dhcp configuration", func() {
err := netManager.SetupDhcp(networks, nil)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedCentosDHCPConfig))
})
It("does not restart network", func() {
err := netManager.SetupDhcp(networks, nil)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(0))
})
ItBroadcastsMACAddresses()
})
})
Describe("SetupManualNetworking", func() {
var errCh chan error
BeforeEach(func() {
errCh = make(chan error)
})
BeforeEach(func() {
fs.WriteFileString("/sys/class/net/eth0/address", "22:00:0a:1f:ac:2a\n")
fs.SetGlob("/sys/class/net/*", []string{"/sys/class/net/eth0"})
})
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns", "gateway"},
IP: "192.168.195.6",
Netmask: "255.255.255.0",
Gateway: "192.168.195.1",
Mac: "22:00:0a:1f:ac:2a",
DNS: []string{"10.80.130.1", "10.80.130.2"},
},
}
It("sets up centos expected ifconfig", func() {
err := netManager.SetupManualNetworking(networks, nil)
Expect(err).ToNot(HaveOccurred())
networkConfig := fs.GetFileTestStat("/etc/sysconfig/network-scripts/ifcfg-eth0")
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(expectedCentosIfcfg))
})
It("sets up centos /etc/resolv.conf", func() {
err := netManager.SetupManualNetworking(networks, nil)
Expect(err).ToNot(HaveOccurred())
resolvConf := fs.GetFileTestStat("/etc/resolv.conf")
Expect(resolvConf).ToNot(BeNil())
Expect(resolvConf.StringContents()).To(Equal(expectedCentosResolvConf))
})
It("restarts networking", func() {
err := netManager.SetupManualNetworking(networks, errCh)
Expect(err).ToNot(HaveOccurred())
fs.GetFileTestStat("/etc/sysconfig/network-scripts/ifcfg-eth0")
fs.GetFileTestStat("/etc/resolv.conf")
<-errCh // wait for all arpings
Expect(len(cmdRunner.RunCommands)).To(Equal(1))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"service", "network", "restart"}))
})
It("starts broadcasting the MAC addresses", func() {
err := netManager.SetupManualNetworking(networks, errCh)
Expect(err).ToNot(HaveOccurred())
fs.GetFileTestStat("/etc/sysconfig/network-scripts/ifcfg-eth0")
fs.GetFileTestStat("/etc/resolv.conf")
<-errCh // wait for all arpings
Expect(addressBroadcaster.BroadcastMACAddressesAddresses).To(Equal([]boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("eth0", "192.168.195.6"),
}))
})
})
})
}