本文整理匯總了Golang中github.com/cloudfoundry/bosh-init/internal/github.com/golang/mock/gomock.Call.Return方法的典型用法代碼示例。如果您正苦於以下問題:Golang Call.Return方法的具體用法?Golang Call.Return怎麽用?Golang Call.Return使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-init/internal/github.com/golang/mock/gomock.Call
的用法示例。
在下文中一共展示了Call.Return方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
}))
})
It("logs start and stop events to the eventLogger", func() {
err := instance.UpdateJobs(deploymentManifest, fakeStage)
Expect(err).NotTo(HaveOccurred())
Expect(fakeStage.PerformCalls).To(Equal([]*fakebiui.PerformCall{
{Name: "Updating instance 'fake-job-name/0'"},
{Name: "Waiting for instance 'fake-job-name/0' to be running"},
}))
})
Context("when instance state building fails", func() {
JustBeforeEach(func() {
expectStateBuild.Return(nil, bosherr.Error("fake-template-err")).Times(1)
})
It("returns an error", func() {
err := instance.UpdateJobs(deploymentManifest, fakeStage)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-template-err"))
})
})
Context("when stopping vm fails", func() {
BeforeEach(func() {
fakeVM.StopErr = bosherr.Error("fake-stop-error")
})
It("logs start and stop events to the eventLogger", func() {
示例2:
Expect(err).ToNot(HaveOccurred())
})
Context("when current VM has been deleted manually (outside of bosh)", func() {
It("migrates the disk content, but does not shutdown the old VM", func() {
expectDeployWithDiskMigrationMissingVM()
err := newDeployCmd().Run(fakeStage, []string{deploymentManifestPath})
Expect(err).ToNot(HaveOccurred())
})
It("ignores DiskNotFound errors", func() {
expectDeployWithDiskMigrationMissingVM()
expectDeleteVM1.Return(bicloud.NewCPIError("delete_vm", bicloud.CmdError{
Type: bicloud.VMNotFoundError,
Message: "fake-vm-not-found-message",
}))
err := newDeployCmd().Run(fakeStage, []string{deploymentManifestPath})
Expect(err).ToNot(HaveOccurred())
})
})
Context("when current disk has been deleted manually (outside of bosh)", func() {
// because there is no cloud.HasDisk, there is no way to know if the disk does not exist, unless attach/delete fails
It("returns an error when attach_disk fails with a DiskNotFound error", func() {
expectDeployWithNoDiskToMigrate()
err := newDeployCmd().Run(fakeStage, []string{deploymentManifestPath})
Expect(err).To(HaveOccurred())
示例3:
Expect(packages).To(ConsistOf([]installation.CompiledPackageRef{
{
Name: "fake-release-package-name-1",
Version: "fake-release-package-fingerprint-1",
BlobstoreID: "fake-compiled-package-blobstore-id-1",
SHA1: "fake-compiled-package-sha1-1",
},
{
Name: "fake-release-package-name-2",
Version: "fake-release-package-fingerprint-2",
BlobstoreID: "fake-compiled-package-blobstore-id-2",
SHA1: "fake-compiled-package-sha1-2",
},
}))
})
Context("when package compilation fails", func() {
JustBeforeEach(func() {
expectCompile.Return([]bistatejob.CompiledPackageRef{}, bosherr.Error("fake-compile-package-2-error")).Times(1)
})
It("returns an error", func() {
_, err := compiler.For(releaseJobs, fakeStage)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-compile-package-2-error"))
})
})
})
})
示例4:
compressor.CompressFilesInDirTarballPath = compiledPackageTarballPath
record := bistatepkg.CompiledPackageRecord{
BlobID: "fake-blob-id",
BlobSHA1: "fake-fingerprint",
}
expectSave = mockCompiledPackageRepo.EXPECT().Save(*pkg, record).AnyTimes()
})
Context("when the compiled package repo already has the package", func() {
JustBeforeEach(func() {
compiledPkgRecord := bistatepkg.CompiledPackageRecord{
BlobSHA1: "fake-fingerprint",
}
expectFind.Return(compiledPkgRecord, true, nil).Times(1)
})
It("skips the compilation", func() {
_, err := compiler.Compile(pkg)
Expect(err).ToNot(HaveOccurred())
Expect(len(runner.RunComplexCommands)).To(Equal(0))
})
})
It("installs all the dependencies for the package", func() {
_, err := compiler.Compile(pkg)
Expect(err).ToNot(HaveOccurred())
blobstoreID, sha1, jobPath := fakeExtractor.ExtractArgsForCall(0)
示例5:
})
Context("the function fails", func() {
It("stops the registry and returns the error", func() {
stopCall.After(spyCall)
err := newInstalation().WithRunningRegistry(logger, fakeStage, func() error {
spy.Record()
return errors.New("blarg!")
})
Expect(err).To(HaveOccurred())
})
})
Context("when starting registry fails", func() {
It("returns an error and doesn't call the function", func() {
startCall.Return(mockRegistryServer, errors.New("registry-start-error"))
spyCall.Times(0)
stopCall.Times(0)
err := newInstalation().WithRunningRegistry(logger, fakeStage, func() error {
spy.Record()
return nil
})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Starting registry: registry-start-error"))
})
})
Context("when stopping registry fails", func() {
Context("when the function fails", func() {
示例6:
mockJobRenderer.EXPECT().Render(releaseJobs[0], jobProperties, globalProperties, deploymentName).Return(renderedJobs[0], nil)
expectRender1 = mockJobRenderer.EXPECT().Render(releaseJobs[1], jobProperties, globalProperties, deploymentName).Return(renderedJobs[1], nil)
})
Describe("Render", func() {
It("returns a new RenderedJobList with all the RenderedJobs", func() {
renderedJobList, err := jobListRenderer.Render(releaseJobs, jobProperties, globalProperties, deploymentName)
Expect(err).ToNot(HaveOccurred())
Expect(renderedJobList.All()).To(Equal([]RenderedJob{
renderedJobs[0],
renderedJobs[1],
}))
})
Context("when rendering a job fails", func() {
JustBeforeEach(func() {
expectRender1.Return(nil, bosherr.Error("fake-render-error"))
})
It("returns an error and cleans up any sucessfully rendered jobs", func() {
renderedJobs[0].EXPECT().DeleteSilently()
_, err := jobListRenderer.Render(releaseJobs, jobProperties, globalProperties, deploymentName)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-render-error"))
})
})
})
})
示例7:
PackageNames: []string{},
Packages: []*birelpkg.Package{},
Properties: map[string]bireljob.PropertyDefinition{},
}
})
JustBeforeEach(func() {
resolver = installation.NewJobResolver(mockReleaseJobResolver)
expectJobResolve = mockReleaseJobResolver.EXPECT().Resolve("fake-cpi-job-name", "fake-cpi-release-name").Return(releaseJob, nil).AnyTimes()
})
Describe("From", func() {
It("when the release does contain a 'cpi' job returns release jobs", func() {
jobs, err := resolver.From(manifest)
Expect(err).ToNot(HaveOccurred())
Expect(jobs).To(Equal([]bireljob.Job{
releaseJob,
}))
})
It("when the release does not contain a 'cpi' job returns an error", func() {
expectJobResolve.Return(bireljob.Job{}, bosherr.Error("fake-job-resolve-error")).Times(1)
_, err := resolver.From(manifest)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-job-resolve-error"))
})
})
})
示例8: rootDesc
//.........這裏部分代碼省略.........
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)
mockReleaseExtractor = mock_release.NewMockExtractor(mockCtrl)
releaseManager = birel.NewManager(logger)
mockRegistryServerManager = mock_registry.NewMockServerManager(mockCtrl)
mockRegistryServer = mock_registry.NewMockServer(mockCtrl)
mockAgentClientFactory = mock_httpagent.NewMockAgentClientFactory(mockCtrl)
mockAgentClient = mock_agentclient.NewMockAgentClient(mockCtrl)
mockAgentClientFactory.EXPECT().NewAgentClient(gomock.Any(), gomock.Any()).Return(mockAgentClient).AnyTimes()
mockCloudFactory = mock_cloud.NewMockFactory(mockCtrl)
mockBlobstoreFactory = mock_blobstore.NewMockFactory(mockCtrl)
mockBlobstore = mock_blobstore.NewMockBlobstore(mockCtrl)
mockBlobstoreFactory.EXPECT().Create(mbusURL).Return(mockBlobstore, nil).AnyTimes()
mockVMManagerFactory = mock_vm.NewMockManagerFactory(mockCtrl)
fakeVMManager = fakebivm.NewFakeManager()
mockVMManagerFactory.EXPECT().NewManager(gomock.Any(), mockAgentClient).Return(fakeVMManager).AnyTimes()
fakeStemcellExtractor = fakebistemcell.NewFakeExtractor()
mockStemcellManager = mock_stemcell.NewMockManager(mockCtrl)
fakeStemcellManagerFactory = fakebistemcell.NewFakeManagerFactory()
fakeReleaseSetParser = fakebirelsetmanifest.NewFakeParser()
fakeInstallationParser = fakebiinstallmanifest.NewFakeParser()
fakeDeploymentParser = fakebideplmanifest.NewFakeParser()
mockLegacyDeploymentStateMigrator = mock_config.NewMockLegacyDeploymentStateMigrator(mockCtrl)
configUUIDGenerator = &fakeuuid.FakeGenerator{}
configUUIDGenerator.GeneratedUUID = directorID
setupDeploymentStateService = biconfig.NewFileSystemDeploymentStateService(fakeFs, configUUIDGenerator, logger, biconfig.DeploymentStatePath(deploymentManifestPath))
fakeDeploymentValidator = fakebideplval.NewFakeValidator()
fakeStage = fakebiui.NewFakeStage()
sha1Calculator = crypto.NewSha1Calculator(fakeFs)
fakeUUIDGenerator = &fakeuuid.FakeGenerator{}
示例9:
installationManifest = biinstallationmanifest.Manifest{}
installStage = fakeui.NewFakeStage()
installation = mocks.NewMockInstallation(mockCtrl)
target = biinstallation.NewTarget("fake-installation-path")
mockInstallerFactory.EXPECT().NewInstaller(target).Return(mockInstaller).AnyTimes()
expectInstall = mockInstaller.EXPECT().Install(installationManifest, gomock.Any())
expectCleanup = mockInstaller.EXPECT().Cleanup(installation).Return(nil)
})
It("should install the CPI and call the passed in function with the installation", func() {
cpiInstaller := release.CpiInstaller{
InstallerFactory: mockInstallerFactory,
}
expectInstall.Return(installation, nil)
var installationArgumentToFunction biinstallation.Installation
err := cpiInstaller.WithInstalledCpiRelease(installationManifest, target, installStage, func(installation biinstallation.Installation) error {
installationArgumentToFunction = installation
return nil
})
Expect(err).ToNot(HaveOccurred())
Expect(installationArgumentToFunction).ToNot(BeNil())
Expect(installationArgumentToFunction).To(Equal(installation))
})
It("starts an 'installing CPI stage' and passes it to the installer", func() {
cpiInstaller := release.CpiInstaller{
示例10:
It("stops the agent and deletes the VM", func() {
gomock.InOrder(
mockAgentClient.EXPECT().Ping().Return("any-state", nil), // ping to make sure agent is responsive
mockAgentClient.EXPECT().Stop(), // stop all jobs
mockAgentClient.EXPECT().ListDisk().Return([]string{"fake-disk-cid"}, nil), // get mounted disks to be unmounted
mockAgentClient.EXPECT().UnmountDisk("fake-disk-cid"),
mockCloud.EXPECT().DeleteVM("fake-vm-cid"),
)
err := deployment.Delete(fakeStage)
Expect(err).ToNot(HaveOccurred())
})
Context("when VM has been deleted manually (outside of bosh)", func() {
BeforeEach(func() {
expectHasVM.Return(false, nil)
})
It("skips agent shutdown & deletes the VM (to ensure related resources are released by the CPI)", func() {
mockCloud.EXPECT().DeleteVM("fake-vm-cid")
err := deployment.Delete(fakeStage)
Expect(err).ToNot(HaveOccurred())
})
It("ignores VMNotFound errors", func() {
mockCloud.EXPECT().DeleteVM("fake-vm-cid").Return(bicloud.NewCPIError("delete_vm", bicloud.CmdError{
Type: bicloud.VMNotFoundError,
Message: "fake-vm-not-found-message",
}))