本文整理匯總了Golang中github.com/cloudfoundry-incubator/ducati-daemon/fakes.Namespace.ExecuteReturns方法的典型用法代碼示例。如果您正苦於以下問題:Golang Namespace.ExecuteReturns方法的具體用法?Golang Namespace.ExecuteReturns怎麽用?Golang Namespace.ExecuteReturns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry-incubator/ducati-daemon/fakes.Namespace
的用法示例。
在下文中一共展示了Namespace.ExecuteReturns方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
Expect(err).NotTo(HaveOccurred())
Expect(namespace.ExecuteCallCount()).To(Equal(1))
})
It("executes the command with the correct context", func() {
err := inNamespace.Execute(context)
Expect(err).NotTo(HaveOccurred())
Expect(command.ExecuteCallCount()).To(Equal(1))
Expect(command.ExecuteArgsForCall(0)).To(Equal(context))
})
Context("when namespace execute fails", func() {
BeforeEach(func() {
namespace.ExecuteReturns(errors.New("go away"))
})
It("wraps and propagates the error", func() {
err := inNamespace.Execute(context)
Expect(err).To(MatchError("execute in namespace: go away"))
})
})
Context("when the target command fails", func() {
BeforeEach(func() {
command.ExecuteReturns(errors.New("i died"))
})
It("wraps and propagates the error", func() {
err := inNamespace.Execute(context)
示例2:
Expect(ns.ExecuteCallCount()).To(Equal(2))
Expect(netlinker.SetNeighArgsForCall(1)).To(Equal(&netlink.Neigh{
LinkIndex: 9876,
HardwareAddr: neigh.HardwareAddr,
Family: syscall.AF_BRIDGE,
State: netlink.NUD_REACHABLE,
Type: 0,
Flags: netlink.NTF_SELF,
IP: neighbor.VTEP,
}))
})
Context("when executing in namespace fails", func() {
BeforeEach(func() {
ns.ExecuteReturns(errors.New("peppers"))
})
It("returns the error", func() {
inserter.HandleResolvedNeighbors(ready, ns, "some-vxlan-name", resolved)
Eventually(ready).Should(Receive(MatchError("namespace execute failed: peppers")))
})
})
Context("when setting a neighbor entry fails", func() {
BeforeEach(func() {
netlinker.SetNeighStub = func(n *netlink.Neigh) error {
if netlinker.SetNeighCallCount() == 1 {
return errors.New("go huskies")
}
return nil
示例3:
written, err := nsWriter.Write([]byte{})
Expect(err).NotTo(HaveOccurred())
Expect(written).To(Equal(100))
})
It("logs the operation", func() {
nsWriter.Write([]byte{})
Expect(logger).To(gbytes.Say("write.write-called.*namespace.*some-inode"))
Expect(logger).To(gbytes.Say("write.write-complete.*namespace.*some-inode"))
})
Context("when setting the namespae fails", func() {
BeforeEach(func() {
ns.ExecuteReturns(errors.New("peanuts"))
})
It("returns a meaningful error", func() {
_, err := nsWriter.Write([]byte{})
Expect(err).To(MatchError("namespace execute: peanuts"))
})
It("logs the error", func() {
nsWriter.Write([]byte{})
Expect(logger).To(gbytes.Say("write.namespace-execute-failed.*peanuts"))
})
})
Context("when the wrapped writer fails", func() {
示例4:
return err
}
err := sb.Setup()
Expect(err).NotTo(HaveOccurred())
Expect(sbNamespace.ExecuteCallCount()).To(Equal(1))
Expect(linkFactory.SetUpCallCount()).To(Equal(1))
linkName := linkFactory.SetUpArgsForCall(0)
Expect(linkName).To(Equal("lo"))
})
Context("when namespace execution fails", func() {
BeforeEach(func() {
sbNamespace.ExecuteReturns(errors.New("boysenberry"))
})
It("returns a meaningful error", func() {
err := sb.Setup()
Expect(err).To(MatchError("setup failed: boysenberry"))
})
})
Context("when setting the link up fails", func() {
BeforeEach(func() {
linkFactory.SetUpReturns(errors.New("tomato"))
})
It("returns a meaningful error", func() {
err := sb.Setup()