当前位置: 首页>>代码示例>>Golang>>正文


Golang FakeMetadataService.RegistryEndpoint方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/infrastructure/fakes.FakeMetadataService.RegistryEndpoint方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeMetadataService.RegistryEndpoint方法的具体用法?Golang FakeMetadataService.RegistryEndpoint怎么用?Golang FakeMetadataService.RegistryEndpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry/bosh-agent/infrastructure/fakes.FakeMetadataService的用法示例。


在下文中一共展示了FakeMetadataService.RegistryEndpoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1:

	BeforeEach(func() {
		metadataService = &fakeinf.FakeMetadataService{}
		platform = &fakeplat.FakePlatform{}
		useServerName = false
		fs = fakesys.NewFakeFileSystem()
	})

	JustBeforeEach(func() {
		logger := boshlog.NewLogger(boshlog.LevelNone)
		registryProvider = NewRegistryProvider(metadataService, platform, useServerName, fs, logger)
	})

	Describe("GetRegistry", func() {
		Context("when metadata service returns registry http endpoint", func() {
			BeforeEach(func() {
				metadataService.RegistryEndpoint = "http://registry-endpoint"
			})

			Context("when registry is configured to not use server name as id", func() {
				BeforeEach(func() { useServerName = false })

				It("returns an http registry that does not use server name as id", func() {
					registry, err := registryProvider.GetRegistry()
					Expect(err).ToNot(HaveOccurred())
					Expect(registry).To(Equal(NewHTTPRegistry(metadataService, platform, false)))
				})
			})

			Context("when registry is configured to use server name as id", func() {
				BeforeEach(func() { useServerName = true })
开发者ID:viovanov,项目名称:bosh-agent,代码行数:30,代码来源:registry_provider_test.go

示例2: describeHTTPRegistry

func describeHTTPRegistry() {
	var (
		metadataService *fakeinf.FakeMetadataService
		registry        Registry
		platform        *fakeplat.FakePlatform
	)

	BeforeEach(func() {
		metadataService = &fakeinf.FakeMetadataService{}
		platform = &fakeplat.FakePlatform{}
		registry = NewHTTPRegistry(metadataService, platform, false)
	})

	Describe("GetSettings", func() {
		var (
			ts           *httptest.Server
			settingsJSON string
		)

		BeforeEach(func() {
			boshRegistryHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				GinkgoRecover()

				Expect(r.Method).To(Equal("GET"))
				Expect(r.URL.Path).To(Equal("/instances/fake-identifier/settings"))

				w.Write([]byte(settingsJSON))
			})

			ts = httptest.NewServer(boshRegistryHandler)
		})

		AfterEach(func() {
			ts.Close()
		})

		Describe("Network bootstrapping", func() {
			BeforeEach(func() {
				settingsJSON = `{"settings": "{\"agent_id\":\"my-agent-id\"}"}`
				metadataService.InstanceID = "fake-identifier"
				metadataService.RegistryEndpoint = ts.URL
				registry = NewHTTPRegistry(metadataService, platform, false)
			})

			Context("when the metadata has Networks information", func() {
				It("configures the network with those settings before hitting the registry", func() {
					networkSettings := boshsettings.Networks{
						"net1": boshsettings.Network{IP: "1.2.3.4"},
						"net2": boshsettings.Network{IP: "2.3.4.5"},
					}
					metadataService.Networks = networkSettings

					_, err := registry.GetSettings()
					Expect(err).ToNot(HaveOccurred())

					Expect(platform.SetupNetworkingCalled).To(BeTrue())
					Expect(platform.SetupNetworkingNetworks).To(Equal(networkSettings))
				})
			})

			Context("when the metadata has no Networks information", func() {
				It("does no network configuration for now (the stemcell set up dhcp already)", func() {
					metadataService.Networks = boshsettings.Networks{}

					_, err := registry.GetSettings()
					Expect(err).ToNot(HaveOccurred())

					Expect(platform.SetupNetworkingCalled).To(BeFalse())
				})
			})

			Context("when the metadata service fails to get Networks information", func() {
				It("wraps the error", func() {
					metadataService.Networks = boshsettings.Networks{}
					metadataService.NetworksErr = errors.New("fake-get-networks-err")

					_, err := registry.GetSettings()
					Expect(err).To(HaveOccurred())

					Expect(err.Error()).To(Equal("Getting networks: fake-get-networks-err"))
				})
			})

			Context("when the SetupNetworking fails", func() {
				It("wraps the error", func() {
					networkSettings := boshsettings.Networks{
						"net1": boshsettings.Network{IP: "1.2.3.4"},
						"net2": boshsettings.Network{IP: "2.3.4.5"},
					}
					metadataService.Networks = networkSettings
					platform.SetupNetworkingErr = errors.New("fake-setup-networking-error")

					_, err := registry.GetSettings()
					Expect(err).To(HaveOccurred())

					Expect(err.Error()).To(Equal("Setting up networks: fake-setup-networking-error"))
				})
			})
		})

//.........这里部分代码省略.........
开发者ID:viovanov,项目名称:bosh-agent,代码行数:101,代码来源:http_registry_test.go


注:本文中的github.com/cloudfoundry/bosh-agent/infrastructure/fakes.FakeMetadataService.RegistryEndpoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。