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


Golang Namespace.ExecuteStub方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry-incubator/ducati-daemon/fakes.Namespace.ExecuteStub方法的典型用法代碼示例。如果您正苦於以下問題:Golang Namespace.ExecuteStub方法的具體用法?Golang Namespace.ExecuteStub怎麽用?Golang Namespace.ExecuteStub使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry-incubator/ducati-daemon/fakes.Namespace的用法示例。


在下文中一共展示了Namespace.ExecuteStub方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

		inNamespace commands.InNamespace
	)

	BeforeEach(func() {
		context = &fakes.Context{}
		command = &fakes.Command{}
		command.StringReturns("some-command")

		namespace = &fakes.Namespace{}
		namespace.NameReturns("namespace-name")

		namespace.ExecuteStub = func(callback func(*os.File) error) error {
			Expect(command.ExecuteCallCount()).To(Equal(0))

			err := callback(nil)

			Expect(command.ExecuteCallCount()).To(Equal(1))
			return err
		}

		inNamespace = commands.InNamespace{
			Namespace: namespace,
			Command:   command,
		}
	})

	It("executes the command in the specified namespace", func() {
		err := inNamespace.Execute(context)
		Expect(err).NotTo(HaveOccurred())

		Expect(namespace.ExecuteCallCount()).To(Equal(1))
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:31,代碼來源:in_namespace_test.go

示例2:

		dnsServer = &fakes.Runner{}
		dnsServerFactory.NewReturns(dnsServer)

		context = &fakes.Context{}
		context.ListenerFactoryReturns(listenerFactory)
		context.LinkFactoryReturns(linkFactory)
		context.AddressManagerReturns(addressManager)
		context.DNSServerFactoryReturns(dnsServerFactory)
		context.SandboxRepositoryReturns(sandboxRepo)
		sandboxRepo.GetReturns(sbox, nil)

		returnedListener = &net.UDPConn{}
		listenerFactory.ListenUDPReturns(returnedListener, nil)

		ns.ExecuteStub = func(callback func(*os.File) error) error {
			return callback(nil)
		}

		startDNS = commands.StartDNSServer{
			ListenAddress: "10.10.10.10:53",
			SandboxName:   "some-sandbox-name",
		}
	})

	It("gets the namespace from the sandbox", func() {
		err := startDNS.Execute(context)
		Expect(err).NotTo(HaveOccurred())

		Expect(sandboxRepo.GetCallCount()).To(Equal(1))
		Expect(sandboxRepo.GetArgsForCall(0)).To(Equal("some-sandbox-name"))
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:30,代碼來源:start_dns_server_test.go

示例3:

		targetNS      *fakes.Namespace
		mySubscriber  *subscriber.Subscriber
		neighChan     chan *watcher.Neigh
		doneChan      chan struct{}
		logger        *lagertest.TestLogger
	)

	BeforeEach(func() {
		fakeNetlinker = &nlfakes.Netlinker{}
		fakeSocket = &nlfakes.NLSocket{}
		neighChan = make(chan *watcher.Neigh, 100)
		doneChan = make(chan struct{})
		logger = lagertest.NewTestLogger("test")
		targetNS = &fakes.Namespace{}
		targetNS.ExecuteStub = func(callback func(*os.File) error) error {
			return callback(nil)
		}

		mySubscriber = &subscriber.Subscriber{
			Netlinker: fakeNetlinker,
			Logger:    logger,
		}

		fakeNetlinker.SubscribeReturns(fakeSocket, nil)
		fakeSocket.ReceiveReturns([]syscall.NetlinkMessage{{Data: []byte("something")}}, nil)
		fakeNetlinker.NeighDeserializeReturns(&netlink.Neigh{}, nil)
	})

	It("subscribes in the sandbox namespace", func() {
		targetNS.ExecuteStub = func(callback func(*os.File) error) error {
			defer GinkgoRecover()
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:31,代碼來源:subscriber_test.go

示例4:

	"github.com/onsi/gomega/gbytes"
)

var _ = Describe("NamespaceWriter", func() {
	var (
		nsWriter *executor.NamespaceWriter
		ns       *fakes.Namespace
		writer   *fakes.Writer
		logger   *lagertest.TestLogger
	)

	BeforeEach(func() {
		ns = &fakes.Namespace{}
		ns.MarshalJSONReturns([]byte(`{ "namespace": "my-namespace", "inode": "some-inode" }`), nil)
		ns.ExecuteStub = func(callback func(*os.File) error) error {
			return callback(nil)
		}

		logger = lagertest.NewTestLogger("test")

		writer = &fakes.Writer{}
		nsWriter = &executor.NamespaceWriter{
			Logger:    logger,
			Namespace: ns,
			Writer:    writer,
		}
	})

	It("writes to the wrapped writer in the associated namespace", func() {
		ns.ExecuteStub = func(callback func(*os.File) error) error {
			Expect(writer.WriteCallCount()).To(Equal(0))
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:31,代碼來源:namespace_writer_test.go

示例5:

		vxlanLink *netlink.Vxlan
		logger    *lagertest.TestLogger
	)

	BeforeEach(func() {
		ns = &fakes.Namespace{}
		netlinker = &nl_fakes.Netlinker{}
		logger = lagertest.NewTestLogger("test")
		vxlanLink = &netlink.Vxlan{
			LinkAttrs: netlink.LinkAttrs{
				Index: 9876,
			},
		}

		ns.ExecuteStub = func(callback func(ns *os.File) error) error {
			return callback(nil)
		}

		netlinker.LinkByNameStub = func(linkName string) (netlink.Link, error) {
			return vxlanLink, nil
		}

		inserter = &neigh.ARPInserter{
			Logger:    logger,
			Netlinker: netlinker,
		}
	})

	Describe("HandleResolvedNeighbors", func() {
		var (
			neigh    watcher.Neigh
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:31,代碼來源:arp_inserter_test.go

示例6:

		sandboxNS = &fakes.Namespace{}
		sandboxRepository.GetReturns(sandboxNS, nil)

		hostNS = &fakes.Namespace{}

		fakeWatcher = &fakes.MissWatcher{}

		startMonitor = commands.StartMonitor{
			HostNamespace: hostNS,
			Watcher:       fakeWatcher,
			SandboxName:   "some-sandbox",
			VxlanLinkName: "some-vxlan-name",
		}

		hostNS.ExecuteStub = func(callback func(_ *os.File) error) error {
			return callback(nil)
		}
	})

	Describe("Execute", func() {
		It("it calls StartMonitor inside the HostNamespace", func() {

			hostNS.ExecuteStub = func(callback func(_ *os.File) error) error {
				Expect(fakeWatcher.StartMonitorCallCount()).To(Equal(0))
				callback(nil)
				Expect(fakeWatcher.StartMonitorCallCount()).To(Equal(1))
				return nil
			}

			err := startMonitor.Execute(context)
			Expect(err).NotTo(HaveOccurred())
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:31,代碼來源:start_monitor_test.go

示例7:

		ns.MarshalJSONReturns([]byte("{}"), nil)

		vxlanLinkName = "some-vxlan-name"
		resolver = &fakes.Resolver{}

		arpInserter = &fakes.ARPInserter{}
		arpInserter.HandleResolvedNeighborsStub = func(ready chan error, _ namespace.Namespace, _ string, _ <-chan watcher.Neighbor) {
			close(ready)
		}

		missWatcher = watcher.New(logger, sub, locker, resolver, arpInserter)

		ns.ExecuteStub = func(callback func(ns *os.File) error) error {
			err := callback(nil)
			if err != nil {
				return fmt.Errorf("callback failed: %s", err)
			}
			return nil
		}
		ns.NameReturns("some-namespace")
	})

	Describe("StartMonitor", func() {
		It("subscribes to sandbox l3 misses", func() {
			missWatcher.StartMonitor(ns, vxlanLinkName)

			Expect(sub.SubscribeCallCount()).To(Equal(1))

			targetNS, _, doneCh := sub.SubscribeArgsForCall(0)
			Expect(targetNS).To(Equal(ns))
			Consistently(doneCh).ShouldNot(BeClosed())
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:31,代碼來源:watcher_test.go

示例8:

		sb          sandbox.Sandbox
		logger      *lagertest.TestLogger
		sbNamespace *fakes.Namespace
		invoker     *fakes.Invoker
		watcher     *fakes.MissWatcher
		linkFactory *fakes.LinkFactory
	)

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("test")
		invoker = &fakes.Invoker{}
		watcher = &fakes.MissWatcher{}
		linkFactory = &fakes.LinkFactory{}
		sbNamespace = &fakes.Namespace{}
		sbNamespace.ExecuteStub = func(callback func(*os.File) error) error {
			return callback(nil)
		}

		sb = sandbox.New(logger, sbNamespace, invoker, linkFactory, watcher)
	})

	Describe("Setup", func() {
		It("brings up the loopback adapter in the sandbox namespace", func() {
			sbNamespace.ExecuteStub = func(callback func(*os.File) error) error {
				Expect(linkFactory.SetUpCallCount()).To(Equal(0))
				err := callback(nil)
				Expect(linkFactory.SetUpCallCount()).To(Equal(1))
				return err
			}

			err := sb.Setup()
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:31,代碼來源:sandbox_test.go

示例9:

			}
			return nil, sandbox.NotFoundError
		}

		context.SandboxRepositoryReturns(sandboxRepo)
		context.SandboxNamespaceRepositoryReturns(namespaceRepository)

		cleanupSandboxCommand = commands.CleanupSandbox{
			SandboxName:     "sandbox-name",
			VxlanDeviceName: "some-vxlan",
		}

		sandboxNS.ExecuteStub = func(callback func(ns *os.File) error) error {
			err := callback(nil)
			if err != nil {
				return fmt.Errorf("callback failed: %s", err)
			}
			return nil
		}
	})

	It("gets the sandbox by name", func() {
		err := cleanupSandboxCommand.Execute(context)
		Expect(err).NotTo(HaveOccurred())

		Expect(sandboxRepo.GetCallCount()).To(Equal(1))
		Expect(sandboxRepo.GetArgsForCall(0)).To(Equal("sandbox-name"))
	})

	Context("when sandbox doesn't exist", func() {
		It("returns without an error", func() {
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:31,代碼來源:cleanup_sandbox_test.go


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