本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes.NewFakeCmdRunner函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFakeCmdRunner函数的具体用法?Golang NewFakeCmdRunner怎么用?Golang NewFakeCmdRunner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFakeCmdRunner函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: describeDummyPlatform
func describeDummyPlatform() {
var (
platform Platform
collector boshstats.Collector
fs boshsys.FileSystem
cmdRunner boshsys.CmdRunner
dirProvider boshdirs.Provider
devicePathResolver boshdpresolv.DevicePathResolver
logger boshlog.Logger
)
BeforeEach(func() {
collector = &fakestats.FakeCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
dirProvider = boshdirs.NewProvider("/fake-dir")
devicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
logger = boshlog.NewLogger(boshlog.LevelNone)
})
JustBeforeEach(func() {
platform = NewDummyPlatform(
collector,
fs,
cmdRunner,
dirProvider,
devicePathResolver,
logger,
)
})
Describe("GetDefaultNetwork", func() {
It("returns the contents of dummy-defaults-network-settings.json since that's what the dummy cpi writes", func() {
settingsFilePath := "/fake-dir/bosh/dummy-default-network-settings.json"
fs.WriteFileString(settingsFilePath, `{"IP": "1.2.3.4"}`)
network, err := platform.GetDefaultNetwork()
Expect(err).NotTo(HaveOccurred())
Expect(network.IP).To(Equal("1.2.3.4"))
})
})
Describe("GetCertManager", func() {
It("returs a dummy cert manager", func() {
certManager := platform.GetCertManager()
Expect(certManager.UpdateCertificates("")).Should(BeNil())
})
})
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:51,代码来源:dummy_platform_test.go
示例2: init
func init() {
Describe("GenericScriptProvider", func() {
It("produces script paths relative to the base directory", func() {
runner := fakesys.NewFakeCmdRunner()
fs := fakesys.NewFakeFileSystem()
dirProvider := boshdir.NewProvider("/the/base/dir")
scriptProvider := scriptrunner.NewJobScriptProvider(runner, fs, dirProvider)
script := scriptProvider.Get("myjob", "the-best-hook-ever")
Expect(script.Path()).To(Equal("/the/base/dir/jobs/myjob/bin/the-best-hook-ever"))
})
})
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:15,代码来源:generic_script_provider_test.go
示例3: init
func init() {
Describe("Testing with Ginkgo", func() {
It("new drain script", func() {
runner := fakesys.NewFakeCmdRunner()
fs := fakesys.NewFakeFileSystem()
dirProvider := boshdir.NewProvider("/var/vcap")
scriptProvider := NewConcreteScriptProvider(runner, fs, dirProvider)
script := scriptProvider.NewScript("foo")
Expect(script.Path()).To(Equal("/var/vcap/jobs/foo/bin/drain"))
})
})
}
开发者ID:tacgomes,项目名称:bosh-agent,代码行数:15,代码来源:concrete_script_provider_test.go
示例4: NewFakePlatform
func NewFakePlatform() (platform *FakePlatform) {
platform = new(FakePlatform)
platform.Fs = fakesys.NewFakeFileSystem()
platform.Runner = fakesys.NewFakeCmdRunner()
platform.FakeCompressor = fakecmd.NewFakeCompressor()
platform.FakeCopier = fakecmd.NewFakeCopier()
platform.FakeVitalsService = fakevitals.NewFakeService()
platform.DevicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
platform.AddUserToGroupsGroups = make(map[string][]string)
platform.SetupSSHPublicKeys = make(map[string]string)
platform.UserPasswords = make(map[string]string)
platform.ScsiDiskMap = make(map[string]string)
platform.GetFileContentsFromDiskDiskPaths = []string{}
platform.GetFileContentsFromDiskFileNames = [][]string{}
platform.GetFileContentsFromDiskContents = map[string][]byte{}
platform.GetFileContentsFromDiskErrs = map[string]error{}
platform.certManager = new(fakecert.FakeManager)
return
}
开发者ID:guoger,项目名称:bosh-agent,代码行数:19,代码来源:fake_platform.go
示例5:
Expect(content).To(ContainSubstring("double-nested-file"))
Expect(dstDir + "/empty-dir").To(beDir())
Expect(dstDir + "/dir/empty-nested-dir").To(beDir())
})
It("returns error if the destination does not exist", func() {
fs.RemoveAll(dstDir)
err := compressor.DecompressFileToDir(fixtureSrcTgz(), dstDir, CompressorOptions{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring(dstDir))
})
It("uses no same owner option", func() {
cmdRunner := fakesys.NewFakeCmdRunner()
compressor := NewTarballCompressor(cmdRunner, fs)
tarballPath := fixtureSrcTgz()
err := compressor.DecompressFileToDir(tarballPath, dstDir, CompressorOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(1).To(Equal(len(cmdRunner.RunCommands)))
Expect(cmdRunner.RunCommands[0]).To(Equal(
[]string{
"tar", "--no-same-owner",
"-xzvf", tarballPath,
"-C", dstDir,
},
))
})
开发者ID:viovanov,项目名称:bosh-agent,代码行数:31,代码来源:tarball_compressor_test.go
示例6:
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
boshretry "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/retrystrategy"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
. "github.com/cloudfoundry/bosh-agent/platform"
)
var _ = Describe("MonitRetryable", func() {
var (
cmdRunner *fakesys.FakeCmdRunner
monitRetryable boshretry.Retryable
)
BeforeEach(func() {
cmdRunner = fakesys.NewFakeCmdRunner()
monitRetryable = NewMonitRetryable(cmdRunner)
})
Describe("Attempt", func() {
Context("when starting monit fails", func() {
BeforeEach(func() {
cmdRunner.AddCmdResult("sv start monit", fakesys.FakeCmdResult{
ExitStatus: 255,
Error: errors.New("fake-start-monit-error"),
})
})
It("is retryable and returns err", func() {
isRetryable, err := monitRetryable.Attempt()
Expect(err).To(HaveOccurred())
开发者ID:viovanov,项目名称:bosh-agent,代码行数:31,代码来源:monit_retryable_test.go
示例7: init
//.........这里部分代码省略.........
boot Bootstrap
defaultNetworkResolver boshsettings.DefaultNetworkResolver
logger boshlog.Logger
dirProvider boshdirs.Provider
)
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"},
}
runner.AddCmdResult(
"readlink -f /dev/vda1",
fakesys.FakeCmdResult{Stdout: "/dev/vda1"},
)
diskManager.FakeRootDevicePartitioner.GetDeviceSizeInBytesSizes["/dev/vda"] = 1024 * 1024 * 1024
udev := boshudev.NewConcreteUdevDevice(runner, logger)
linuxCdrom := boshcdrom.NewLinuxCdrom("/dev/sr0", udev, runner)
linuxCdutil := boshcdrom.NewCdUtil(dirProvider.SettingsDir(), fs, linuxCdrom, logger)
compressor := boshcmd.NewTarballCompressor(runner, fs)
copier := boshcmd.NewCpCopier(runner, fs, logger)
sigarCollector := boshsigar.NewSigarStatsCollector(&sigar.ConcreteSigar{})
vitalsService := boshvitals.NewService(sigarCollector, dirProvider)
开发者ID:guoger,项目名称:bosh-agent,代码行数:66,代码来源:bootstrap_test.go
示例8: 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))
//.........这里部分代码省略.........
开发者ID:guoger,项目名称:bosh-agent,代码行数:101,代码来源:linux_platform_test.go
示例9: describeUbuntuNetManager
func describeUbuntuNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
addressBroadcaster *fakearp.FakeAddressBroadcaster
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{}
netManager = NewUbuntuNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
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"}))
})
})
Context("when specified more than one DNS", func() {
It("extracts all DNS servers from the network configured as default DNS", func() {
networks := boshsettings.Networks{
"default": factory.Network{
IP: "10.10.0.32",
Netmask: "255.255.255.0",
//.........这里部分代码省略.........
开发者ID:viovanov,项目名称:bosh-agent,代码行数:101,代码来源:ubuntu_net_manager_test.go
示例10: describeCentosNetManager
func describeCentosNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
addressBroadcaster *fakearp.FakeAddressBroadcaster
netManager Manager
interfaceConfigurationCreator InterfaceConfigurationCreator
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
ipResolver = &fakeip.FakeResolver{}
logger := boshlog.NewLogger(boshlog.LevelNone)
interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger)
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
netManager = NewCentosNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
addressBroadcaster,
logger,
)
})
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
}
Describe("SetupNetworking", func() {
var (
dhcpNetwork boshsettings.Network
staticNetwork boshsettings.Network
expectedNetworkConfigurationForStatic string
expectedNetworkConfigurationForDHCP string
expectedDhclientConfiguration string
)
BeforeEach(func() {
dhcpNetwork = boshsettings.Network{
Type: "dynamic",
Default: []string{"dns"},
DNS: []string{"8.8.8.8", "9.9.9.9"},
Mac: "fake-dhcp-mac-address",
}
staticNetwork = boshsettings.Network{
Type: "manual",
IP: "1.2.3.4",
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
Mac: "fake-static-mac-address",
}
expectedNetworkConfigurationForStatic = `DEVICE=ethstatic
BOOTPROTO=static
IPADDR=1.2.3.4
NETMASK=255.255.255.0
BROADCAST=1.2.3.255
GATEWAY=3.4.5.6
ONBOOT=yes
PEERDNS=no
DNS1=8.8.8.8
DNS2=9.9.9.9
`
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))
//.........这里部分代码省略.........
开发者ID:viovanov,项目名称:bosh-agent,代码行数:101,代码来源:centos_net_manager_test.go
示例11:
It("returns an error when deleting old certs fails", func() {
fakeFs.RemoveAllError = errors.New("NOT ALLOW")
fakeFs.WriteFileString(fmt.Sprintf("%s/bosh-trusted-cert-1.crt", certBasePath), "goodbye")
fakeFs.SetGlob(fmt.Sprintf("%s/bosh-trusted-cert-*", certBasePath), []string{
fmt.Sprintf("%s/bosh-trusted-cert-1.crt", certBasePath),
})
err := certManager.UpdateCertificates("")
Expect(err).To(HaveOccurred())
})
}
Context("Ubuntu", func() {
BeforeEach(func() {
fakeFs = fakesys.NewFakeFileSystem()
fakeCmd = fakesys.NewFakeCmdRunner()
fakeCmd.AddCmdResult("/usr/sbin/update-ca-certificates", fakesys.FakeCmdResult{
Stdout: "",
Stderr: "",
ExitStatus: 0,
Sticky: true,
})
certManager = cert.NewUbuntuCertManager(fakeFs, fakeCmd, log)
})
SharedLinuxCertManagerExamples("/usr/local/share/ca-certificates", "/usr/sbin/update-ca-certificates")
// TODO this test can be shared if there is a way to update existing FakeCmdRunner command specs
It("executes update cert command", func() {
fakeCmd = fakesys.NewFakeCmdRunner()
fakeCmd.AddCmdResult("/usr/sbin/update-ca-certificates -f", fakesys.FakeCmdResult{
开发者ID:viovanov,项目名称:bosh-agent,代码行数:31,代码来源:cert_manager_test.go
注:本文中的github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes.NewFakeCmdRunner函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论