本文整理汇总了Golang中github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes.NewFakeFileSystem函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFakeFileSystem函数的具体用法?Golang NewFakeFileSystem怎么用?Golang NewFakeFileSystem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFakeFileSystem函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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:vestel,项目名称:bosh-init,代码行数:51,代码来源:dummy_platform_test.go
示例2: 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:vestel,项目名称:bosh-init,代码行数:19,代码来源:fake_platform.go
示例3: GetIP
func (ia failingInterfaceAddress) GetIP() (string, error) {
return "", errors.New("fake-get-ip-err")
}
var _ = Describe("arping", func() {
const arpingIterations = 6
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
arping AddressBroadcaster
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
logger := boshlog.NewLogger(boshlog.LevelNone)
arping = NewArping(cmdRunner, fs, logger, arpingIterations, 0, 0)
})
Describe("BroadcastMACAddresses", func() {
BeforeEach(func() {
fs.WriteFile("/sys/class/net/eth0", []byte{})
fs.WriteFile("/sys/class/net/eth1", []byte{})
})
It("runs arping commands for each interface", func() {
addresses := []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("eth0", "192.168.195.6"),
boship.NewSimpleInterfaceAddress("eth1", "127.0.0.1"),
开发者ID:vestel,项目名称:bosh-init,代码行数:30,代码来源:arping_test.go
示例4:
releaseJob bireljob.Job
releaseJobs []bireljob.Job
fakeStage *fakebiui.FakeStage
releasePackage1 *birelpkg.Package
releasePackage2 *birelpkg.Package
expectCompile *gomock.Call
)
BeforeEach(func() {
mockDependencyCompiler = mock_state_job.NewMockDependencyCompiler(mockCtrl)
fakeFS = fakeboshsys.NewFakeFileSystem()
fakeStage = fakebiui.NewFakeStage()
releasePackage1 = &birelpkg.Package{
Name: "fake-release-package-name-1",
Fingerprint: "fake-release-package-fingerprint-1",
SHA1: "fake-release-package-sha1-1",
Dependencies: []*birelpkg.Package{},
ExtractedPath: "/extracted-release-path/extracted_packages/fake-release-package-name-1",
}
releasePackage2 = &birelpkg.Package{
Name: "fake-release-package-name-2",
Fingerprint: "fake-release-package-fingerprint-2",
SHA1: "fake-release-package-sha1-2",
开发者ID:vestel,项目名称:bosh-init,代码行数:30,代码来源:package_compiler_test.go
示例5:
Expect(err).ToNot(HaveOccurred())
Expect(1).To(Equal(len(cmdRunner.RunCommands)))
Expect(cmdRunner.RunCommands[0]).To(Equal(
[]string{
"tar", "--same-owner",
"-xzvf", tarballPath,
"-C", dstDir,
},
))
})
})
Describe("CleanUp", func() {
It("removes tarball path", func() {
fs := fakesys.NewFakeFileSystem()
compressor := NewTarballCompressor(cmdRunner, fs)
err := fs.WriteFileString("/fake-tarball.tar", "")
Expect(err).ToNot(HaveOccurred())
err = compressor.CleanUp("/fake-tarball.tar")
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists("/fake-tarball.tar")).To(BeFalse())
})
It("returns error if removing tarball path fails", func() {
fs := fakesys.NewFakeFileSystem()
compressor := NewTarballCompressor(cmdRunner, fs)
开发者ID:vestel,项目名称:bosh-init,代码行数:30,代码来源:tarball_compressor_test.go
示例6: 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:vestel,项目名称:bosh-init,代码行数:101,代码来源:ubuntu_net_manager_test.go
示例7: init
func init() {
Describe("settingsService", func() {
var (
fs *fakesys.FakeFileSystem
fakeDefaultNetworkResolver *fakenet.FakeDefaultNetworkResolver
fakeSettingsSource *fakes.FakeSettingsSource
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
fakeDefaultNetworkResolver = &fakenet.FakeDefaultNetworkResolver{}
fakeSettingsSource = &fakes.FakeSettingsSource{}
})
buildService := func() (Service, *fakesys.FakeFileSystem) {
logger := boshlog.NewLogger(boshlog.LevelNone)
service := NewService(fs, "/setting/path.json", fakeSettingsSource, fakeDefaultNetworkResolver, logger)
return service, fs
}
Describe("LoadSettings", func() {
var (
fetchedSettings Settings
fetcherFuncErr error
service Service
)
BeforeEach(func() {
fetchedSettings = Settings{}
fetcherFuncErr = nil
})
JustBeforeEach(func() {
fakeSettingsSource.SettingsValue = fetchedSettings
fakeSettingsSource.SettingsErr = fetcherFuncErr
service, fs = buildService()
})
Context("when settings fetcher succeeds fetching settings", func() {
BeforeEach(func() {
fetchedSettings = Settings{AgentID: "some-new-agent-id"}
})
Context("when settings contain at most one dynamic network", func() {
BeforeEach(func() {
fetchedSettings.Networks = Networks{
"fake-net-1": Network{Type: NetworkTypeDynamic},
}
})
It("updates the service with settings from the fetcher", func() {
err := service.LoadSettings()
Expect(err).NotTo(HaveOccurred())
Expect(service.GetSettings().AgentID).To(Equal("some-new-agent-id"))
})
It("persists settings to the settings file", func() {
err := service.LoadSettings()
Expect(err).NotTo(HaveOccurred())
json, err := json.Marshal(fetchedSettings)
Expect(err).NotTo(HaveOccurred())
fileContent, err := fs.ReadFile("/setting/path.json")
Expect(err).NotTo(HaveOccurred())
Expect(fileContent).To(Equal(json))
})
It("returns any error from writing to the setting file", func() {
fs.WriteFileError = errors.New("fs-write-file-error")
err := service.LoadSettings()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fs-write-file-error"))
})
})
})
Context("when settings fetcher fails fetching settings", func() {
BeforeEach(func() {
fetcherFuncErr = errors.New("fake-fetch-error")
})
Context("when a settings file exists", func() {
Context("when settings contain at most one dynamic network", func() {
BeforeEach(func() {
fs.WriteFile("/setting/path.json", []byte(`{
"agent_id":"some-agent-id",
"networks": {"fake-net-1": {"type": "dynamic"}}
}`))
fakeDefaultNetworkResolver.GetDefaultNetworkNetwork = Network{
IP: "fake-resolved-ip",
Netmask: "fake-resolved-netmask",
Gateway: "fake-resolved-gateway",
}
})
It("returns settings from the settings file with resolved network", func() {
err := service.LoadSettings()
//.........这里部分代码省略.........
开发者ID:vestel,项目名称:bosh-init,代码行数:101,代码来源:service_test.go
示例8: rootDesc
func rootDesc() {
var (
fakeRelease *fakebirel.FakeRelease
stemcell bistemcell.ExtractedStemcell
deploymentRepo *fakebiconfig.FakeDeploymentRepo
releaseRepo *fakebiconfig.FakeReleaseRepo
stemcellRepo *fakebiconfig.FakeStemcellRepo
fakeSHA1Calculator *fakebicrypto.FakeSha1Calculator
deploymentRecord Record
releases []release.Release
)
BeforeEach(func() {
fakeRelease = &fakebirel.FakeRelease{
ReleaseName: "fake-release-name",
ReleaseVersion: "fake-release-version",
}
releases = []release.Release{fakeRelease}
fakeFS := fakesys.NewFakeFileSystem()
stemcell = bistemcell.NewExtractedStemcell(
bistemcell.Manifest{
Name: "fake-stemcell-name",
Version: "fake-stemcell-version",
},
"fake-extracted-path",
fakeFS,
)
deploymentRepo = fakebiconfig.NewFakeDeploymentRepo()
releaseRepo = &fakebiconfig.FakeReleaseRepo{}
stemcellRepo = fakebiconfig.NewFakeStemcellRepo()
fakeSHA1Calculator = fakebicrypto.NewFakeSha1Calculator()
deploymentRecord = NewRecord(deploymentRepo, releaseRepo, stemcellRepo, fakeSHA1Calculator)
})
Describe("IsDeployed", func() {
BeforeEach(func() {
stemcellRecord := biconfig.StemcellRecord{
ID: "fake-stemcell-id",
Name: "fake-stemcell-name",
Version: "fake-stemcell-version",
CID: "fake-stemcell-cid",
}
stemcellRepo.SetFindCurrentBehavior(stemcellRecord, true, nil)
deploymentRepo.SetFindCurrentBehavior("fake-manifest-sha1", true, nil)
fakeSHA1Calculator.SetCalculateBehavior(map[string]fakebicrypto.CalculateInput{
"fake-manifest-path": fakebicrypto.CalculateInput{
Sha1: "fake-manifest-sha1",
Err: nil,
},
})
})
Context("when the stemcell and manifest do not change", func() {
Context("when no release is currently deployed", func() {
BeforeEach(func() {
releaseRepo.ListReturns([]biconfig.ReleaseRecord{}, nil)
})
It("returns false", func() {
isDeployed, err := deploymentRecord.IsDeployed("fake-manifest-path", releases, stemcell)
Expect(err).ToNot(HaveOccurred())
Expect(isDeployed).To(BeFalse())
})
})
Context("when the same release is currently deployed", func() {
BeforeEach(func() {
releaseRecords := []biconfig.ReleaseRecord{{
ID: "fake-release-id",
Name: fakeRelease.Name(),
Version: fakeRelease.Version(),
}}
releaseRepo.ListReturns(releaseRecords, nil)
})
It("returns true", func() {
isDeployed, err := deploymentRecord.IsDeployed("fake-manifest-path", releases, stemcell)
Expect(err).ToNot(HaveOccurred())
Expect(isDeployed).To(BeTrue())
})
})
Context("when a different version of the same release is currently deployed", func() {
BeforeEach(func() {
Expect("other-version").ToNot(Equal(fakeRelease.Version()))
releaseRecords := []biconfig.ReleaseRecord{{
ID: "fake-release-id-2",
Name: fakeRelease.Name(),
Version: "other-version",
}}
releaseRepo.ListReturns(releaseRecords, nil)
})
It("returns false", func() {
isDeployed, err := deploymentRecord.IsDeployed("fake-manifest-path", releases, stemcell)
Expect(err).ToNot(HaveOccurred())
Expect(isDeployed).To(BeFalse())
})
})
//.........这里部分代码省略.........
开发者ID:vestel,项目名称:bosh-init,代码行数:101,代码来源:record_test.go
示例9: init
func init() {
Describe("execCmdRunner", func() {
var (
runner CmdRunner
)
BeforeEach(func() {
runner = NewExecCmdRunner(boshlog.NewLogger(boshlog.LevelNone))
})
Describe("RunComplexCommand", func() {
It("run complex command with working directory", func() {
cmd := Command{
Name: "ls",
Args: []string{"-l"},
WorkingDir: ".",
}
stdout, stderr, status, err := runner.RunComplexCommand(cmd)
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(ContainSubstring("exec_cmd_runner_fixtures"))
Expect(stdout).To(ContainSubstring("total"))
Expect(stderr).To(BeEmpty())
Expect(status).To(Equal(0))
})
It("run complex command with env", func() {
cmd := Command{
Name: "env",
Env: map[string]string{
"FOO": "BAR",
},
}
stdout, stderr, status, err := runner.RunComplexCommand(cmd)
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(ContainSubstring("FOO=BAR"))
Expect(stdout).To(ContainSubstring("PATH="))
Expect(stderr).To(BeEmpty())
Expect(status).To(Equal(0))
})
It("runs complex command with specific env", func() {
cmd := Command{
Name: "env",
Env: map[string]string{
"FOO": "BAR",
},
UseIsolatedEnv: true,
}
stdout, stderr, status, err := runner.RunComplexCommand(cmd)
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(ContainSubstring("FOO=BAR"))
Expect(stdout).ToNot(ContainSubstring("PATH="))
Expect(stderr).To(BeEmpty())
Expect(status).To(Equal(0))
})
It("run complex command with stdin", func() {
input := "This is STDIN\nWith another line."
cmd := Command{
Name: "cat",
Args: []string{"/dev/stdin"},
Stdin: strings.NewReader(input),
}
stdout, stderr, status, err := runner.RunComplexCommand(cmd)
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(Equal(input))
Expect(stderr).To(BeEmpty())
Expect(status).To(Equal(0))
})
It("prints stdout/stderr to provided I/O object", func() {
fs := fakesys.NewFakeFileSystem()
stdoutFile, err := fs.OpenFile("/fake-stdout-path", os.O_RDWR, os.FileMode(0644))
Expect(err).ToNot(HaveOccurred())
stderrFile, err := fs.OpenFile("/fake-stderr-path", os.O_RDWR, os.FileMode(0644))
Expect(err).ToNot(HaveOccurred())
cmd := Command{
Name: "bash",
Args: []string{"-c", "echo fake-out >&1; echo fake-err >&2"},
Stdout: stdoutFile,
Stderr: stderrFile,
}
stdout, stderr, status, err := runner.RunComplexCommand(cmd)
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(BeEmpty())
Expect(stderr).To(BeEmpty())
Expect(status).To(Equal(0))
stdoutContents := make([]byte, 1024)
_, err = stdoutFile.Read(stdoutContents)
Expect(err).ToNot(HaveOccurred())
Expect(string(stdoutContents)).To(ContainSubstring("fake-out"))
stderrContents := make([]byte, 1024)
_, err = stderrFile.Read(stderrContents)
Expect(err).ToNot(HaveOccurred())
//.........这里部分代码省略.........
开发者ID:vestel,项目名称:bosh-init,代码行数:101,代码来源:exec_cmd_runner_test.go
示例10: init
func init() {
Describe("Testing with Ginkgo", func() {
It("linux format when using swap fs", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext4" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemSwap)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mkswap", "/dev/xvda1"}))
})
It("linux format when using swap fs and partition is swap", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="swap" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemSwap)
Expect(1).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[0]).To(Equal([]string{"blkid", "-p", "/dev/xvda1"}))
})
It("linux format when using ext4 fs with lazy itable support", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeFs.WriteFile("/sys/fs/ext4/features/lazy_itable_init", []byte{})
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda2", FileSystemExt4)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mke2fs", "-t", "ext4", "-j", "-E", "lazy_itable_init=1", "/dev/xvda2"}))
})
It("linux format when using ext4 fs without lazy itable support", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda2", FileSystemExt4)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mke2fs", "-t", "ext4", "-j", "/dev/xvda2"}))
})
It("linux format when using ext4 fs and partition is ext4", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext4" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemExt4)
Expect(1).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[0]).To(Equal([]string{"blkid", "-p", "/dev/xvda1"}))
})
})
}
开发者ID:vestel,项目名称:bosh-init,代码行数:65,代码来源:linux_formatter_test.go
示例11: rootDesc
func rootDesc() {
var mockCtrl *gomock.Controller
BeforeEach(func() {
mockCtrl = gomock.NewController(GinkgoT())
})
AfterEach(func() {
mockCtrl.Finish()
})
Describe("Run", func() {
var (
command bicmd.Cmd
fakeFs *fakesys.FakeFileSystem
stdOut *gbytes.Buffer
stdErr *gbytes.Buffer
userInterface biui.UI
sha1Calculator crypto.SHA1Calculator
manifestSHA1 string
mockDeployer *mock_deployment.MockDeployer
mockInstaller *mock_install.MockInstaller
mockInstallerFactory *mock_install.MockInstallerFactory
mockReleaseExtractor *mock_release.MockExtractor
releaseManager birel.Manager
mockRegistryServerManager *mock_registry.MockServerManager
mockRegistryServer *mock_registry.MockServer
mockAgentClient *mock_agentclient.MockAgentClient
mockAgentClientFactory *mock_httpagent.MockAgentClientFactory
mockCloudFactory *mock_cloud.MockFactory
fakeCPIRelease *fakebirel.FakeRelease
logger boshlog.Logger
mockBlobstoreFactory *mock_blobstore.MockFactory
mockBlobstore *mock_blobstore.MockBlobstore
mockVMManagerFactory *mock_vm.MockManagerFactory
fakeVMManager *fakebivm.FakeManager
fakeStemcellExtractor *fakebistemcell.FakeExtractor
mockStemcellManager *mock_stemcell.MockManager
fakeStemcellManagerFactory *fakebistemcell.FakeManagerFactory
fakeReleaseSetParser *fakebirelsetmanifest.FakeParser
fakeInstallationParser *fakebiinstallmanifest.FakeParser
fakeDeploymentParser *fakebideplmanifest.FakeParser
mockLegacyDeploymentStateMigrator *mock_config.MockLegacyDeploymentStateMigrator
setupDeploymentStateService biconfig.DeploymentStateService
fakeDeploymentValidator *fakebideplval.FakeValidator
directorID = "generated-director-uuid"
fakeUUIDGenerator *fakeuuid.FakeGenerator
configUUIDGenerator *fakeuuid.FakeGenerator
fakeStage *fakebiui.FakeStage
deploymentManifestPath string
deploymentStatePath string
cpiReleaseTarballPath string
stemcellTarballPath string
extractedStemcell bistemcell.ExtractedStemcell
expectDeploy *gomock.Call
mbusURL = "http://fake-mbus-user:[email protected]"
releaseSetManifest birelsetmanifest.Manifest
boshDeploymentManifest bideplmanifest.Manifest
installationManifest biinstallmanifest.Manifest
cloud bicloud.Cloud
cloudStemcell bistemcell.CloudStemcell
expectLegacyMigrate *gomock.Call
expectStemcellUpload *gomock.Call
expectStemcellDeleteUnused *gomock.Call
expectCPIReleaseExtract *gomock.Call
expectInstall *gomock.Call
expectNewCloud *gomock.Call
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
stdOut = gbytes.NewBuffer()
stdErr = gbytes.NewBuffer()
userInterface = biui.NewWriterUI(stdOut, stdErr, logger)
fakeFs = fakesys.NewFakeFileSystem()
fakeFs.EnableStrictTempRootBehavior()
deploymentManifestPath = "/path/to/manifest.yml"
deploymentStatePath = "/path/to/manifest-state.json"
fakeFs.RegisterOpenFile(deploymentManifestPath, &fakesys.FakeFile{
Stats: &fakesys.FakeFileStats{FileType: fakesys.FakeFileTypeFile},
})
fakeFs.WriteFileString(deploymentManifestPath, "")
mockDeployer = mock_deployment.NewMockDeployer(mockCtrl)
mockInstaller = mock_install.NewMockInstaller(mockCtrl)
mockInstallerFactory = mock_install.NewMockInstallerFactory(mockCtrl)
//.........这里部分代码省略.........
开发者ID:hanzhefeng,项目名称:bosh-init,代码行数:101,代码来源:deploy_cmd_test.go
示例12: createBlobManager
func createBlobManager() (blobManager BlobManager, fs *fakesys.FakeFileSystem) {
fs = fakesys.NewFakeFileSystem()
blobManager = NewBlobManager(fs, "/var/vcap/micro_bosh/data/cache")
return
}
开发者ID:vestel,项目名称:bosh-init,代码行数:5,代码来源:blob_manager_test.go
示例13: 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:vestel,项目名称:bosh-init,代码行数:101,代码来源:centos_net_manager_test.go
示例14: rootDesc
func rootDesc() {
var (
repo ReleaseRepo
deploymentStateService DeploymentStateService
fs *fakesys.FakeFileSystem
fakeUUIDGenerator *fakeuuid.FakeGenerator
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
fs = fakesys.NewFakeFileSystem()
fakeUUIDGenerator = &fakeuuid.FakeGenerator{}
fakeUUIDGenerator.GeneratedUUID = "fake-uuid"
deploymentStateService = NewFileSystemDeploymentStateService(fs, fakeUUIDGenerator, logger, "/fake/path")
deploymentStateService.Load()
repo = NewReleaseRepo(deploymentStateService, fakeUUIDGenerator)
})
Describe("List", func() {
Context("when a current release exists", func() {
BeforeEach(func() {
conf, err := deploymentStateService.Load()
Expect(err).ToNot(HaveOccurred())
conf.Releases = []ReleaseRecord{
ReleaseRecord{ID: "fake-guid-a", Name: "fake-name-a", Version: "fake-version-a"},
ReleaseRecord{ID: "fake-guid-b", Name: "fake-name-b", Version: "fake-version-b"},
}
err = deploymentStateService.Save(conf)
Expect(err).ToNot(HaveOccurred())
})
It("returns existing release", func() {
records, err := repo.List()
Expect(err).ToNot(HaveOccurred())
Expect(records).To(Equal([]ReleaseRecord{
{
ID: "fake-guid-a",
Name: "fake-name-a",
Version: "fake-version-a",
},
{
ID: "fake-guid-b",
Name: "fake-name-b",
Version: "fake-version-b",
},
}))
})
})
Context("when there are no releases recorded", func() {
It("returns not found", func() {
records, err := repo.List()
Expect(err).ToNot(HaveOccurred())
Expect(records).To(HaveLen(0))
})
})
Context("when the config service fails to load", func() {
BeforeEach(func() {
fs.ReadFileError = errors.New("kaboom")
})
It("returns an error", func() {
_, err := repo.List()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Loading existing config"))
})
})
})
Describe("Update", func() {
Context("when there are no existing releases", func() {
It("saves the provided releases to the config file", func() {
err := repo.Update([]release.Release{
fakerelease.New("name1", "1"),
fakerelease.New("name2", "2"),
})
Expect(err).ToNot(HaveOccurred())
conf, err := deploymentStateService.Load()
Expect(err).ToNot(HaveOccurred())
Expect(conf.Releases).To(ConsistOf(
ReleaseRecord{ID: "fake-uuid", Name: "name1", Version: "1"},
ReleaseRecord{ID: "fake-uuid", Name: "name2", Version: "2"},
))
})
})
Context("when the existing releases exactly match the provided releases", func() {
BeforeEach(func() {
conf, err := deploymentStateService.Load()
Expect(err).ToNot(HaveOccurred())
conf.Releases = []ReleaseRecord{
ReleaseRecord{ID: "old-uuid", Name: "name1", Version: "1"},
ReleaseRecord{ID: "old-uuid", Name: "name2", Version: "2"},
}
err = deploymentStateService.Save(conf)
Expect(err).ToNot(HaveOccurred())
})
})
//.........这里部分代码省略.........
开发者ID:vestel,项目名称:bosh-init,代码行数:101,代码来源:release_repo_test.go
注:本文中的github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes.NewFakeFileSystem函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论