本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.GetFileTestStat方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.GetFileTestStat方法的具體用法?Golang FakeFileSystem.GetFileTestStat怎麽用?Golang FakeFileSystem.GetFileTestStat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.GetFileTestStat方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
It("returns an error if creation of parent directory fails", func() {
fs.MkdirAllError = errors.New("fake-mkdir-error")
_, _, err := fileBundle.Install(sourcePath)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-mkdir-error"))
})
It("sets correct permissions on install path", func() {
fs.Chmod(sourcePath, os.FileMode(0700))
_, _, err := fileBundle.Install(sourcePath)
Expect(err).NotTo(HaveOccurred())
fileStats := fs.GetFileTestStat(installPath)
Expect(fileStats).ToNot(BeNil())
Expect(fileStats.FileType).To(Equal(fakesys.FakeFileType(fakesys.FakeFileTypeDir)))
Expect(fileStats.FileMode).To(Equal(os.FileMode(0755)))
})
It("is idempotent", func() {
actualFs, path, err := fileBundle.Install(sourcePath)
Expect(err).NotTo(HaveOccurred())
Expect(actualFs).To(Equal(fs))
Expect(path).To(Equal(installPath))
otherSourcePath := createSourcePath()
actualFs, path, err = fileBundle.Install(otherSourcePath)
Expect(err).NotTo(HaveOccurred())
示例2: describeLinuxPlatform
func describeLinuxPlatform() {
var (
collector *fakestats.FakeCollector
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
diskManager *fakedisk.FakeDiskManager
dirProvider boshdirs.Provider
devicePathResolver *fakedpresolv.FakeDevicePathResolver
platform Platform
cdutil *fakedevutil.FakeDeviceUtil
compressor boshcmd.Compressor
copier boshcmd.Copier
vitalsService boshvitals.Service
netManager *fakenet.FakeManager
certManager *fakecert.FakeManager
monitRetryStrategy *fakeretry.FakeRetryStrategy
fakeDefaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
options LinuxOptions
logger boshlog.Logger
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
collector = &fakestats.FakeCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
diskManager = fakedisk.NewFakeDiskManager()
dirProvider = boshdirs.NewProvider("/fake-dir")
cdutil = fakedevutil.NewFakeDeviceUtil()
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
copier = boshcmd.NewCpCopier(cmdRunner, fs, logger)
vitalsService = boshvitals.NewService(collector, dirProvider)
netManager = &fakenet.FakeManager{}
certManager = new(fakecert.FakeManager)
monitRetryStrategy = fakeretry.NewFakeRetryStrategy()
devicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
fakeDefaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
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() {
platform = NewLinuxPlatform(
fs,
cmdRunner,
collector,
compressor,
copier,
dirProvider,
vitalsService,
cdutil,
diskManager,
netManager,
certManager,
monitRetryStrategy,
devicePathResolver,
5*time.Millisecond,
options,
logger,
fakeDefaultNetworkResolver,
)
})
Describe("SetupRuntimeConfiguration", func() {
It("setups runtime configuration", func() {
err := platform.SetupRuntimeConfiguration()
Expect(err).NotTo(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(1))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"bosh-agent-rc"}))
})
})
Describe("CreateUser", func() {
It("creates user", func() {
expectedUseradd := []string{
"useradd",
"-m",
"-b", "/some/path/to/home",
"-s", "/bin/bash",
"-p", "bar-pwd",
"foo-user",
}
err := platform.CreateUser("foo-user", "bar-pwd", "/some/path/to/home")
Expect(err).NotTo(HaveOccurred())
basePathStat := fs.GetFileTestStat("/some/path/to/home")
Expect(basePathStat.FileType).To(Equal(fakesys.FakeFileTypeDir))
//.........這裏部分代碼省略.........
示例3: describeUbuntuNetManager
//.........這裏部分代碼省略.........
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
dns-nameservers 8.8.8.8 9.9.9.9`
})
It("writes interfaces in /etc/network/interfaces in alphabetic order", func() {
anotherDHCPNetwork := boshsettings.Network{
Type: "dynamic",
Default: []string{"dns"},
DNS: []string{"8.8.8.8", "9.9.9.9"},
Mac: "fake-another-mac-address",
}
stubInterfaces(map[string]boshsettings.Network{
"ethstatic": staticNetwork,
"ethdhcp1": dhcpNetwork,
"ethdhcp0": anotherDHCPNetwork,
})
err := netManager.SetupNetworking(boshsettings.Networks{
"dhcp-network-1": dhcpNetwork,
"dhcp-network-2": anotherDHCPNetwork,
"static-network": staticNetwork,
}, nil)
Expect(err).ToNot(HaveOccurred())
networkConfig := fs.GetFileTestStat("/etc/network/interfaces")
Expect(networkConfig).ToNot(BeNil())
expectedNetworkConfigurationForStaticAndDhcp = `# Generated by bosh-agent
auto lo
iface lo inet loopback
auto ethdhcp0
iface ethdhcp0 inet dhcp
auto ethdhcp1
iface ethdhcp1 inet dhcp
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
dns-nameservers 8.8.8.8 9.9.9.9`
Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfigurationForStaticAndDhcp))
})
It("writes /etc/network/interfaces without dns-namservers if there are no dns servers", func() {
staticNetworkWithoutDNS := boshsettings.Network{
Type: "manual",
IP: "1.2.3.4",
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
Mac: "fake-static-mac-address",
}
示例4:
})
Describe("Get", func() {
It("fetches the local blob contents", func() {
fs.WriteFileString(fakeBlobstorePath+"/fake-blob-id", "fake contents")
tempFile, err := fs.TempFile("bosh-blobstore-local-TestLocalGet")
Expect(err).ToNot(HaveOccurred())
fs.ReturnTempFile = tempFile
defer fs.RemoveAll(tempFile.Name())
_, err = blobstore.Get("fake-blob-id", "")
Expect(err).ToNot(HaveOccurred())
fileStats := fs.GetFileTestStat(tempFile.Name())
Expect(fileStats).ToNot(BeNil())
Expect("fake contents").To(Equal(fileStats.StringContents()))
})
It("errs when temp file create errs", func() {
fs.TempFileError = errors.New("fake-error")
fileName, err := blobstore.Get("fake-blob-id", "")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-error"))
Expect(fileName).To(BeEmpty())
})
It("errs when copy file errs", func() {
示例5: init
func init() {
Describe("concreteV1Service", func() {
var (
fs *fakesys.FakeFileSystem
specPath = "/spec.json"
service V1Service
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
service = NewConcreteV1Service(fs, specPath)
})
Describe("Get", func() {
Context("when filesystem has a spec file", func() {
BeforeEach(func() {
fs.WriteFileString(specPath, `{"deployment":"fake-deployment-name"}`)
})
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{Deployment: "fake-deployment-name"}))
})
It("returns error if reading spec from filesystem errs", func() {
fs.ReadFileError = errors.New("fake-read-error")
spec, err := service.Get()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
Context("when filesystem does not have a spec file", func() {
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
})
Describe("Set", func() {
newSpec := V1ApplySpec{Deployment: "fake-deployment-name"}
It("writes spec to filesystem", func() {
err := service.Set(newSpec)
Expect(err).ToNot(HaveOccurred())
specPathStats := fs.GetFileTestStat(specPath)
Expect(specPathStats).ToNot(BeNil())
boshassert.MatchesJSONBytes(GinkgoT(), newSpec, specPathStats.Content)
})
It("returns error if writing spec to filesystem errs", func() {
fs.WriteFileError = errors.New("fake-write-error")
err := service.Set(newSpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
Describe("PopulateDHCPNetworks", func() {
var settings boshsettings.Settings
var unresolvedSpec V1ApplySpec
var staticSpec NetworkSpec
var dhcpSpec NetworkSpec
var manualSetting boshsettings.Network
var dynamicSetting boshsettings.Network
BeforeEach(func() {
settings = boshsettings.Settings{
Networks: boshsettings.Networks{},
}
manualSetting = boshsettings.Network{
Type: "manual",
IP: "fake-manual-ip",
Netmask: "fake-manual-netmask",
Gateway: "fake-manual-gateway",
Mac: "fake-manual-mac",
}
dynamicSetting = boshsettings.Network{
Type: "dynamic",
IP: "fake-dynamic-ip",
Netmask: "fake-dynamic-netmask",
Gateway: "fake-dynamic-gateway",
}
unresolvedSpec = V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{},
}
staticSpec = NetworkSpec{
Fields: map[string]interface{}{
"ip": "fake-net1-ip",
"netmask": "fake-net1-netmask",
"gateway": "fake-net1-gateway",
//.........這裏部分代碼省略.........
示例6: describeCentosNetManager
//.........這裏部分代碼省略.........
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() {
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
示例7: init
//.........這裏部分代碼省略.........
It("returns error when walking the tree of files fails", func() {
fs.WalkErr = errors.New("fake-walk-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-walk-error"))
})
It("installs bundle from decompressed tmp path of a job template", func() {
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 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())