本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/infrastructure/fakes.FakeMetadataService類的典型用法代碼示例。如果您正苦於以下問題:Golang FakeMetadataService類的具體用法?Golang FakeMetadataService怎麽用?Golang FakeMetadataService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FakeMetadataService類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: describeMultiSourceMetadataService
func describeMultiSourceMetadataService() {
var (
metadataService MetadataService
service1 fakeinf.FakeMetadataService
service2 fakeinf.FakeMetadataService
)
BeforeEach(func() {
service1 = fakeinf.FakeMetadataService{
Available: false,
PublicKey: "fake-public-key-1",
InstanceID: "fake-instance-id-1",
ServerName: "fake-server-name-1",
RegistryEndpoint: "fake-registry-endpoint-1",
Networks: boshsettings.Networks{"net-1": boshsettings.Network{}},
}
service2 = fakeinf.FakeMetadataService{
Available: false,
PublicKey: "fake-public-key-2",
InstanceID: "fake-instance-id-2",
ServerName: "fake-server-name-2",
RegistryEndpoint: "fake-registry-endpoint-2",
Networks: boshsettings.Networks{"net-2": boshsettings.Network{}},
}
})
Context("when the first service is available", func() {
BeforeEach(func() {
service1.Available = true
metadataService = NewMultiSourceMetadataService(service1, service2)
})
Describe("GetPublicKey", func() {
It("returns public key from the available service", func() {
publicKey, err := metadataService.GetPublicKey()
Expect(err).NotTo(HaveOccurred())
Expect(publicKey).To(Equal("fake-public-key-1"))
})
})
Describe("GetInstanceID", func() {
It("returns instance ID from the available service", func() {
instanceID, err := metadataService.GetInstanceID()
Expect(err).NotTo(HaveOccurred())
Expect(instanceID).To(Equal("fake-instance-id-1"))
})
})
Describe("GetServerName", func() {
It("returns server name from the available service", func() {
serverName, err := metadataService.GetServerName()
Expect(err).NotTo(HaveOccurred())
Expect(serverName).To(Equal("fake-server-name-1"))
})
})
Describe("GetRegistryEndpoint", func() {
It("returns registry endpoint from the available service", func() {
registryEndpoint, err := metadataService.GetRegistryEndpoint()
Expect(err).NotTo(HaveOccurred())
Expect(registryEndpoint).To(Equal("fake-registry-endpoint-1"))
})
})
Describe("GetNetworks", func() {
It("returns network settings from the available service", func() {
networks, err := metadataService.GetNetworks()
Expect(err).NotTo(HaveOccurred())
Expect(networks).To(Equal(boshsettings.Networks{"net-1": boshsettings.Network{}}))
})
})
})
Context("when the first service is unavailable", func() {
BeforeEach(func() {
service1.Available = false
service2.Available = true
metadataService = NewMultiSourceMetadataService(service1, service2)
})
Describe("GetPublicKey", func() {
It("returns public key from the available service", func() {
publicKey, err := metadataService.GetPublicKey()
Expect(err).NotTo(HaveOccurred())
Expect(publicKey).To(Equal("fake-public-key-2"))
})
})
Describe("GetInstanceID", func() {
It("returns instance ID from the available service", func() {
instanceID, err := metadataService.GetInstanceID()
Expect(err).NotTo(HaveOccurred())
Expect(instanceID).To(Equal("fake-instance-id-2"))
})
})
Describe("GetServerName", func() {
It("returns server name from the available service", func() {
serverName, err := metadataService.GetServerName()
//.........這裏部分代碼省略.........
示例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:
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/infrastructure"
fakeinf "github.com/cloudfoundry/bosh-agent/infrastructure/fakes"
boshlog "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/logger"
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes"
fakeplat "github.com/cloudfoundry/bosh-agent/platform/fakes"
)
var _ = Describe("RegistryProvider", func() {
var (
metadataService *fakeinf.FakeMetadataService
platform *fakeplat.FakePlatform
useServerName bool
fs *fakesys.FakeFileSystem
registryProvider RegistryProvider
)
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)
})
示例4:
import (
"errors"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo"
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega"
. "github.com/cloudfoundry/bosh-agent/infrastructure"
fakeinf "github.com/cloudfoundry/bosh-agent/infrastructure/fakes"
boshlog "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/logger"
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
)
var _ = Describe("ComplexSettingsSource", func() {
var (
metadataService *fakeinf.FakeMetadataService
registryProvider *fakeinf.FakeRegistryProvider
source ComplexSettingsSource
)
BeforeEach(func() {
metadataService = &fakeinf.FakeMetadataService{}
registryProvider = &fakeinf.FakeRegistryProvider{}
logger := boshlog.NewLogger(boshlog.LevelNone)
source = NewComplexSettingsSource(metadataService, registryProvider, logger)
})
Describe("PublicSSHKeyForUsername", func() {
It("returns an empty string", func() {
metadataService.PublicKey = "public-key"
publicKey, err := source.PublicSSHKeyForUsername("fake-username")