本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/agent/script/fakes.FakeScript.RunReturns方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeScript.RunReturns方法的具体用法?Golang FakeScript.RunReturns怎么用?Golang FakeScript.RunReturns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/bosh-agent/agent/script/fakes.FakeScript
的用法示例。
在下文中一共展示了FakeScript.RunReturns方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
barScript := &fakescript.FakeScript{}
barScript.TagReturns("bar")
jobScriptProvider.NewDrainScriptStub = func(jobName string, params boshdrain.ScriptParams) boshscript.Script {
Expect(params).To(Equal(boshdrain.NewUpdateParams(currentSpec, newSpec)))
if jobName == "foo" {
return fooScript
} else if jobName == "bar" {
return barScript
} else {
panic("Non-matching update drain script created")
}
}
parallelScript.RunReturns(nil)
value, err := act()
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal(0))
Expect(parallelScript.RunCallCount()).To(Equal(1))
Expect(jobScriptProvider.NewParallelScriptCallCount()).To(Equal(1))
scriptName, scripts := jobScriptProvider.NewParallelScriptArgsForCall(0)
Expect(scriptName).To(Equal("drain"))
Expect(scripts).To(Equal([]boshscript.Script{fooScript, barScript}))
})
It("returns an error when parallel script fails", func() {
parallelScript.RunReturns(errors.New("fake-error"))
示例2:
})
})
Context("when script exists", func() {
var existingScript *fakescript.FakeScript
BeforeEach(func() {
existingScript = &fakescript.FakeScript{}
existingScript.TagReturns("fake-job-1")
existingScript.PathReturns("path/to/script1")
existingScript.ExistsReturns(true)
scripts = append(scripts, existingScript)
})
It("executes the script and succeeds", func() {
existingScript.RunReturns(nil)
err := parallelScript.Run()
Expect(err).ToNot(HaveOccurred())
Expect(existingScript.RunCallCount()).To(Equal(1))
})
It("gives an error when script fails", func() {
existingScript.RunReturns(errors.New("fake-error"))
err := parallelScript.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("1 of 1 run-me scripts failed. Failed Jobs: fake-job-1."))
Expect(existingScript.RunCallCount()).To(Equal(1))