當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Namespace.ExecuteReturns方法代碼示例

本文整理匯總了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)
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:31,代碼來源:in_namespace_test.go

示例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
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:30,代碼來源:arp_inserter_test.go

示例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() {
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:30,代碼來源:namespace_writer_test.go

示例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()
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:31,代碼來源:sandbox_test.go


注:本文中的github.com/cloudfoundry-incubator/ducati-daemon/fakes.Namespace.ExecuteReturns方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。