本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/platform/fakes.FakePlatform.SetupNetworkingErr方法的典型用法代码示例。如果您正苦于以下问题:Golang FakePlatform.SetupNetworkingErr方法的具体用法?Golang FakePlatform.SetupNetworkingErr怎么用?Golang FakePlatform.SetupNetworkingErr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/bosh-agent/platform/fakes.FakePlatform
的用法示例。
在下文中一共展示了FakePlatform.SetupNetworkingErr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: describeHTTPMetadataService
func describeHTTPMetadataService() {
var (
dnsResolver *fakeinf.FakeDNSResolver
platform *fakeplat.FakePlatform
logger boshlog.Logger
metadataService MetadataService
)
BeforeEach(func() {
dnsResolver = &fakeinf.FakeDNSResolver{}
platform = fakeplat.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
metadataService = NewHTTPMetadataService("fake-metadata-host", dnsResolver, platform, logger)
})
ItEnsuresMinimalNetworkSetup := func(subject func() (string, error)) {
Context("when no networks are configured", func() {
BeforeEach(func() {
platform.GetConfiguredNetworkInterfacesInterfaces = []string{}
})
It("sets up DHCP network", func() {
_, err := subject()
Expect(err).ToNot(HaveOccurred())
Expect(platform.SetupNetworkingCalled).To(BeTrue())
Expect(platform.SetupNetworkingNetworks).To(Equal(boshsettings.Networks{
"eth0": boshsettings.Network{
Type: "dynamic",
},
}))
})
Context("when setting up DHCP fails", func() {
BeforeEach(func() {
platform.SetupNetworkingErr = errors.New("fake-network-error")
})
It("returns an error", func() {
_, err := subject()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-network-error"))
})
})
})
}
Describe("IsAvailable", func() {
It("returns true", func() {
Expect(metadataService.IsAvailable()).To(BeTrue())
})
})
Describe("GetPublicKey", func() {
var (
ts *httptest.Server
)
BeforeEach(func() {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
GinkgoRecover()
Expect(r.Method).To(Equal("GET"))
Expect(r.URL.Path).To(Equal("/latest/meta-data/public-keys/0/openssh-key"))
w.Write([]byte("fake-public-key"))
})
ts = httptest.NewServer(handler)
metadataService = NewHTTPMetadataService(ts.URL, dnsResolver, platform, logger)
})
AfterEach(func() {
ts.Close()
})
ItEnsuresMinimalNetworkSetup(func() (string, error) {
return metadataService.GetPublicKey()
})
It("returns fetched public key", func() {
publicKey, err := metadataService.GetPublicKey()
Expect(err).NotTo(HaveOccurred())
Expect(publicKey).To(Equal("fake-public-key"))
})
})
Describe("GetInstanceID", func() {
var (
ts *httptest.Server
)
BeforeEach(func() {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
GinkgoRecover()
Expect(r.Method).To(Equal("GET"))
Expect(r.URL.Path).To(Equal("/latest/meta-data/instance-id"))
//.........这里部分代码省略.........
示例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"))
})
})
})
//.........这里部分代码省略.........
示例3: describeHTTPMetadataService
func describeHTTPMetadataService() {
var (
metadataHeaders map[string]string
dnsResolver *fakeinf.FakeDNSResolver
platform *fakeplat.FakePlatform
logger boshlog.Logger
metadataService MetadataService
)
BeforeEach(func() {
metadataHeaders = make(map[string]string)
metadataHeaders["key"] = "value"
dnsResolver = &fakeinf.FakeDNSResolver{}
platform = fakeplat.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
metadataService = NewHTTPMetadataService("fake-metadata-host", metadataHeaders, "/user-data", "/instanceid", "/ssh-keys", dnsResolver, platform, logger)
})
ItEnsuresMinimalNetworkSetup := func(subject func() (string, error)) {
Context("when no networks are configured", func() {
BeforeEach(func() {
platform.GetConfiguredNetworkInterfacesInterfaces = []string{}
})
It("sets up DHCP network", func() {
_, err := subject()
Expect(err).ToNot(HaveOccurred())
Expect(platform.SetupNetworkingCalled).To(BeTrue())
Expect(platform.SetupNetworkingNetworks).To(Equal(boshsettings.Networks{
"eth0": boshsettings.Network{
Type: "dynamic",
},
}))
})
Context("when setting up DHCP fails", func() {
BeforeEach(func() {
platform.SetupNetworkingErr = errors.New("fake-network-error")
})
It("returns an error", func() {
_, err := subject()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-network-error"))
})
})
})
}
Describe("IsAvailable", func() {
It("returns true", func() {
Expect(metadataService.IsAvailable()).To(BeTrue())
})
})
Describe("GetPublicKey", func() {
var (
ts *httptest.Server
sshKeysPath string
)
BeforeEach(func() {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
Expect(r.Method).To(Equal("GET"))
Expect(r.URL.Path).To(Equal("/ssh-keys"))
Expect(r.Header.Get("key")).To(Equal("value"))
w.Write([]byte("fake-public-key"))
})
ts = httptest.NewServer(handler)
})
AfterEach(func() {
ts.Close()
})
Context("when the ssh keys path is present", func() {
BeforeEach(func() {
sshKeysPath = "/ssh-keys"
metadataService = NewHTTPMetadataService(ts.URL, metadataHeaders, "/user-data", "/instanceid", sshKeysPath, dnsResolver, platform, logger)
})
It("returns fetched public key", func() {
publicKey, err := metadataService.GetPublicKey()
Expect(err).NotTo(HaveOccurred())
Expect(publicKey).To(Equal("fake-public-key"))
})
ItEnsuresMinimalNetworkSetup(func() (string, error) {
return metadataService.GetPublicKey()
})
})
Context("when the ssh keys path is not present", func() {
BeforeEach(func() {
sshKeysPath = ""
metadataService = NewHTTPMetadataService(ts.URL, metadataHeaders, "/user-data", "/instanceid", sshKeysPath, dnsResolver, platform, logger)
//.........这里部分代码省略.........