本文整理匯總了Golang中bosh/system/fakes.FakeCmdRunner類的典型用法代碼示例。如果您正苦於以下問題:Golang FakeCmdRunner類的具體用法?Golang FakeCmdRunner怎麽用?Golang FakeCmdRunner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeCmdRunner類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
const expectedUbuntuDHCPConfig = `# 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 zz.zz.zz.zz, yy.yy.yy.yy, xx.xx.xx.xx;
`
Describe("ubuntuNetManager", func() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
defaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
netManager NetManager
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
defaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
logger := boshlog.NewLogger(boshlog.LevelNone)
netManager = NewUbuntuNetManager(fs, cmdRunner, defaultNetworkResolver, 1*time.Millisecond, logger)
})
Describe("SetupDhcp", func() {
networks := boshsettings.Networks{
"bosh": boshsettings.Network{
Default: []string{"dns"},
DNS: []string{"xx.xx.xx.xx", "yy.yy.yy.yy", "zz.zz.zz.zz"},
},
"vip": boshsettings.Network{
Default: []string{},
DNS: []string{"aa.aa.aa.aa"},
},
}
ItRestartsDhcp := func() {
Context("when ifconfig version is 0.7", func() {
BeforeEach(func() {
cmdRunner.AddCmdResult("ifup --version", fakesys.FakeCmdResult{
Stdout: "ifup version 0.7.47",
})
})
It("restarts dhclient", func() {
err := netManager.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(3))
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"ifdown", "-a", "--no-loopback"}))
Expect(cmdRunner.RunCommands[2]).To(Equal([]string{"ifup", "-a", "--no-loopback"}))
})
})
Context("when ifconfig version is 0.6", func() {
BeforeEach(func() {
cmdRunner.AddCmdResult("ifup --version", fakesys.FakeCmdResult{
Stdout: "ifup version 0.6.0",
})
})
It("restarts dhclient", func() {
err := netManager.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(3))
Expect(cmdRunner.RunCommands[1]).To(Equal([]string{"ifdown", "-a", "--exclude=lo"}))
Expect(cmdRunner.RunCommands[2]).To(Equal([]string{"ifup", "-a", "--exclude=lo"}))
})
})
}
ItUpdatesDhcp3Config := func() {
It("updates /etc/dhcp3/dhclient.conf", func() {
err := netManager.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp3/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedUbuntuDHCPConfig))
})
}
ItUpdatesDhcpConfig := func() {
It("updates /etc/dhcp/dhclient.conf", func() {
err := netManager.SetupDhcp(networks)
Expect(err).ToNot(HaveOccurred())
dhcpConfig := fs.GetFileTestStat("/etc/dhcp/dhclient.conf")
Expect(dhcpConfig).ToNot(BeNil())
Expect(dhcpConfig.StringContents()).To(Equal(expectedUbuntuDHCPConfig))
})
}
//.........這裏部分代碼省略.........
示例2:
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "bosh/agent/action"
boshas "bosh/agent/applier/applyspec"
fakeas "bosh/agent/applier/applyspec/fakes"
boshsys "bosh/system"
fakesys "bosh/system/fakes"
)
var _ = Describe("RunErrand", func() {
var (
specService *fakeas.FakeV1Service
cmdRunner *fakesys.FakeCmdRunner
action RunErrandAction
)
BeforeEach(func() {
specService = fakeas.NewFakeV1Service()
cmdRunner = fakesys.NewFakeCmdRunner()
action = NewRunErrand(specService, "/fake-jobs-dir", cmdRunner)
})
It("is asynchronous", func() {
Expect(action.IsAsynchronous()).To(BeTrue())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
示例3:
package net_test
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "bosh/platform/net"
fakesys "bosh/system/fakes"
)
var _ = Describe("cmdRoutesSeacher", func() {
var (
runner *fakesys.FakeCmdRunner
searcher RoutesSearcher
)
BeforeEach(func() {
runner = fakesys.NewFakeCmdRunner()
searcher = NewCmdRoutesSearcher(runner)
})
Describe("SearchRoutes", func() {
Context("when running command succeeds", func() {
It("returns parsed routes information", func() {
runner.AddCmdResult("route -n", fakesys.FakeCmdResult{
Stdout: `Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.79.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
示例4:
package cdrom_test
import (
. "bosh/platform/cdrom"
fakeudev "bosh/platform/cdrom/udevdevice/fakes"
fakesys "bosh/system/fakes"
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("LinuxCdrom", func() {
var (
udev *fakeudev.FakeUdevDevice
runner *fakesys.FakeCmdRunner
cd Cdrom
)
BeforeEach(func() {
udev = fakeudev.NewFakeUdevDevice()
runner = fakesys.NewFakeCmdRunner()
})
JustBeforeEach(func() {
cd = NewLinuxCdrom("/dev/sr0", udev, runner)
})
Describe("WaitForMedia", func() {
It("polls the cdrom to force udev to notice it", func() {
err := cd.WaitForMedia()
Expect(err).NotTo(HaveOccurred())
示例5:
import (
"errors"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "bosh/agent/cmdrunner"
boshsys "bosh/system"
fakesys "bosh/system/fakes"
)
var _ = Describe("FileLoggingCmdRunner", func() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
cmd boshsys.Command
runner CmdRunner
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
runner = NewFileLoggingCmdRunner(fs, cmdRunner, "/fake-base-dir", 15)
cmd = boshsys.Command{
Name: "fake-cmd",
Args: []string{"fake-args"},
Env: map[string]string{"fake-env-key": "fake-env-var"},
WorkingDir: "/fake-working-dir",
}
})
示例6:
s.mounts = s.mounts[1:]
return result, nil
}
const swaponUsageOutput = `Filename Type Size Used Priority
/dev/swap partition 78180316 0 -1
`
const swaponUsageOutputWithOtherDevice = `Filename Type Size Used Priority
/dev/swap2 partition 78180316 0 -1
`
var _ = Describe("linuxMounter", func() {
var (
runner *fakesys.FakeCmdRunner
mountsSearcher *fakedisk.FakeMountsSearcher
mounter Mounter
)
BeforeEach(func() {
runner = fakesys.NewFakeCmdRunner()
mountsSearcher = &fakedisk.FakeMountsSearcher{}
mounter = NewLinuxMounter(runner, mountsSearcher, 1*time.Millisecond)
})
Describe("Mount", func() {
It("allows to mount disk at given mount point", func() {
err := mounter.Mount("/dev/foo", "/mnt/foo")
Expect(err).ToNot(HaveOccurred())
Expect(1).To(Equal(len(runner.RunCommands)))
Expect(runner.RunCommands[0]).To(Equal([]string{"mount", "/dev/foo", "/mnt/foo"}))
示例7:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
boshassert "bosh/assert"
. "bosh/blobstore"
boshdir "bosh/settings/directories"
fakesys "bosh/system/fakes"
fakeuuid "bosh/uuid/fakes"
)
var _ = Describe("external", func() {
var (
fs *fakesys.FakeFileSystem
runner *fakesys.FakeCmdRunner
uuidGen *fakeuuid.FakeGenerator
configPath string
blobstore Blobstore
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
uuidGen = &fakeuuid.FakeGenerator{}
dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
configPath = filepath.Join(dirProvider.EtcDir(), "blobstore-fake-provider.json")
blobstore = NewExternalBlobstore("fake-provider", map[string]interface{}{}, fs, runner, uuidGen, configPath)
})
Describe("Validate", func() {
It("external validate writes config file", func() {
示例8:
package disk_test
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "bosh/platform/disk"
fakesys "bosh/system/fakes"
)
var _ = Describe("cmdMountsSeacher", func() {
var (
runner *fakesys.FakeCmdRunner
searcher MountsSearcher
)
BeforeEach(func() {
runner = fakesys.NewFakeCmdRunner()
searcher = NewCmdMountsSearcher(runner)
})
Describe("SearchMounts", func() {
Context("when running command succeeds", func() {
It("returns parsed mount information", func() {
runner.AddCmdResult("mount", fakesys.FakeCmdResult{
Stdout: `devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
/dev/sda1 on /boot type ext2 (rw)
none on /tmp/warden/cgroup type tmpfs (rw)`,
示例9: JobChange
jobNextState string
jobNextStateErr error
}
func (p fakeDrainParams) JobChange() (change string) { return p.jobChange }
func (p fakeDrainParams) HashChange() (change string) { return p.hashChange }
func (p fakeDrainParams) UpdatedPackages() (pkgs []string) { return p.updatedPackages }
func (p fakeDrainParams) JobState() (string, error) { return p.jobState, p.jobStateErr }
func (p fakeDrainParams) JobNextState() (string, error) { return p.jobNextState, p.jobNextStateErr }
var _ = Describe("ConcreteDrainScript", func() {
var (
runner *fakesys.FakeCmdRunner
fs *fakesys.FakeFileSystem
drainScript ConcreteDrainScript
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
runner = fakesys.NewFakeCmdRunner()
drainScript = NewConcreteDrainScript(fs, runner, "/fake/script")
})
Describe("Run", func() {
var (
params fakeDrainParams
)
BeforeEach(func() {
示例10:
boshlog "bosh/logger"
. "bosh/platform/net"
fakearp "bosh/platform/net/arp/fakes"
fakenet "bosh/platform/net/fakes"
boship "bosh/platform/net/ip"
fakeip "bosh/platform/net/ip/fakes"
boshsettings "bosh/settings"
fakesys "bosh/system/fakes"
)
var _ = Describe("ubuntuNetManager", func() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
defaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
ipResolver *fakeip.FakeIPResolver
addressBroadcaster *fakearp.FakeAddressBroadcaster
netManager NetManager
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
defaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
ipResolver = &fakeip.FakeIPResolver{}
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
logger := boshlog.NewLogger(boshlog.LevelNone)
netManager = NewUbuntuNetManager(
fs,
cmdRunner,
defaultNetworkResolver,