本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/platform/fakes.NewFakePlatform函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFakePlatform函數的具體用法?Golang NewFakePlatform怎麽用?Golang NewFakePlatform使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewFakePlatform函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
Describe("ReleaseApplySpec", func() {
var (
platform *fakeplatform.FakePlatform
action ReleaseApplySpecAction
)
BeforeEach(func() {
platform = fakeplatform.NewFakePlatform()
action = NewReleaseApplySpec(platform)
})
It("is synchronous", func() {
Expect(action.IsAsynchronous()).To(BeFalse())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("run", func() {
err := platform.GetFs().WriteFileString("/var/vcap/micro/apply_spec.json", `{"json":["objects"]}`)
Expect(err).ToNot(HaveOccurred())
value, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal(map[string]interface{}{"json": []interface{}{"objects"}}))
})
})
}
示例2: buildSSHAction
func buildSSHAction(settingsService boshsettings.Service) (*fakeplatform.FakePlatform, SSHAction) {
platform := fakeplatform.NewFakePlatform()
dirProvider := boshdirs.NewProvider("/foo")
logger := boshlog.NewLogger(boshlog.LevelNone)
action := NewSSH(settingsService, platform, dirProvider, logger)
return platform, action
}
示例3: init
func init() {
Describe("Stop", func() {
var (
jobSupervisor *fakejobsuper.FakeJobSupervisor
platform *fakeplatform.FakePlatform
settingsService *fakesettings.FakeSettingsService
logger boshlog.Logger
specService *fakeas.FakeV1Service
dualDCSupport *nimbus.DualDCSupport
action StopAction
)
BeforeEach(func() {
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
platform = fakeplatform.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
specService = fakeas.NewFakeV1Service()
settingsService = &fakesettings.FakeSettingsService{}
dualDCSupport = nimbus.NewDualDCSupport(
platform.GetRunner(),
platform.GetFs(),
platform.GetDirProvider(),
specService,
settingsService,
logger,
)
action = NewStop(jobSupervisor, dualDCSupport, platform)
})
It("is asynchronous", func() {
Expect(action.IsAsynchronous()).To(BeTrue())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("returns stopped", func() {
stopped, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(stopped).To(Equal("stopped"))
})
It("stops job supervisor services", func() {
_, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(jobSupervisor.Stopped).To(BeTrue())
})
})
}
示例4: init
func init() {
Describe("ListDisk", func() {
var (
settingsService *fakesettings.FakeSettingsService
platform *fakeplatform.FakePlatform
logger boshlog.Logger
action ListDiskAction
)
BeforeEach(func() {
settingsService = &fakesettings.FakeSettingsService{}
platform = fakeplatform.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
action = NewListDisk(settingsService, platform, logger)
})
It("list disk should be synchronous", func() {
Expect(action.IsAsynchronous()).To(BeFalse())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("list disk run", func() {
platform.MountedDevicePaths = []string{"/dev/sdb", "/dev/sdc"}
settingsService.Settings.Disks = boshsettings.Disks{
Persistent: map[string]interface{}{
"volume-1": "/dev/sda",
"volume-2": "/dev/sdb",
"volume-3": "/dev/sdc",
},
}
value, err := action.Run()
Expect(err).ToNot(HaveOccurred())
values, ok := value.([]string)
Expect(ok).To(BeTrue())
Expect(values).To(ContainElement("volume-2"))
Expect(values).To(ContainElement("volume-3"))
Expect(len(values)).To(Equal(2))
})
})
}
示例5: init
func init() {
Describe("bootstrap", func() {
Describe("Run", func() {
var (
platform *fakeplatform.FakePlatform
dirProvider boshdir.Provider
settingsSource *fakeinf.FakeSettingsSource
settingsService *fakesettings.FakeSettingsService
)
BeforeEach(func() {
platform = fakeplatform.NewFakePlatform()
dirProvider = boshdir.NewProvider("/var/vcap")
settingsSource = &fakeinf.FakeSettingsSource{}
settingsService = &fakesettings.FakeSettingsService{}
})
bootstrap := func() error {
logger := boshlog.NewLogger(boshlog.LevelNone)
return NewBootstrap(platform, dirProvider, settingsService, logger).Run()
}
It("sets up runtime configuration", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.SetupRuntimeConfigurationWasInvoked).To(BeTrue())
})
Describe("SSH tunnel setup for registry", func() {
It("returns error without configuring ssh on the platform if getting public key fails", func() {
settingsService.PublicKeyErr = errors.New("fake-get-public-key-err")
err := bootstrap()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-public-key-err"))
Expect(platform.SetupSSHCalled).To(BeFalse())
})
Context("when public key is not empty", func() {
BeforeEach(func() {
settingsService.PublicKey = "fake-public-key"
})
It("gets the public key and sets up ssh via the platform", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.SetupSSHPublicKey).To(Equal("fake-public-key"))
Expect(platform.SetupSSHUsername).To(Equal("vcap"))
})
It("returns error if configuring ssh on the platform fails", func() {
platform.SetupSSHErr = errors.New("fake-setup-ssh-err")
err := bootstrap()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-setup-ssh-err"))
})
})
Context("when public key key is empty", func() {
BeforeEach(func() {
settingsSource.PublicKey = ""
})
It("gets the public key and does not setup SSH", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.SetupSSHCalled).To(BeFalse())
})
})
})
It("sets up hostname", func() {
settingsService.Settings.AgentID = "foo-bar-baz-123"
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(platform.SetupHostnameHostname).To(Equal("foo-bar-baz-123"))
})
It("fetches initial settings", func() {
err := bootstrap()
Expect(err).NotTo(HaveOccurred())
Expect(settingsService.SettingsWereLoaded).To(BeTrue())
})
It("returns error from loading initial settings", func() {
settingsService.LoadSettingsError = errors.New("fake-load-error")
err := bootstrap()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-load-error"))
})
It("sets up networking", func() {
//.........這裏部分代碼省略.........
示例6: buildMigrateDiskAction
func buildMigrateDiskAction() (platform *fakeplatform.FakePlatform, action MigrateDiskAction) {
platform = fakeplatform.NewFakePlatform()
dirProvider := boshdirs.NewProvider("/foo")
action = NewMigrateDisk(platform, dirProvider)
return
}
示例7: init
func init() {
Describe("Agent", func() {
var (
logger boshlog.Logger
handler *fakembus.FakeHandler
platform *fakeplatform.FakePlatform
actionDispatcher *fakeagent.FakeActionDispatcher
jobSupervisor *fakejobsuper.FakeJobSupervisor
specService *fakeas.FakeV1Service
syslogServer *fakesyslog.FakeServer
settingsService *fakesettings.FakeSettingsService
uuidGenerator *fakeuuid.FakeGenerator
timeService *fakeclock.FakeClock
agent Agent
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
handler = &fakembus.FakeHandler{}
platform = fakeplatform.NewFakePlatform()
actionDispatcher = &fakeagent.FakeActionDispatcher{}
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
syslogServer = &fakesyslog.FakeServer{}
settingsService = &fakesettings.FakeSettingsService{}
uuidGenerator = &fakeuuid.FakeGenerator{}
timeService = fakeclock.NewFakeClock(time.Now())
agent = New(
logger,
handler,
platform,
actionDispatcher,
jobSupervisor,
specService,
syslogServer,
5*time.Millisecond,
settingsService,
uuidGenerator,
timeService,
)
})
Describe("Run", func() {
It("lets dispatcher handle requests arriving via handler", func() {
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
expectedResp := boshhandler.NewValueResponse("pong")
actionDispatcher.DispatchResp = expectedResp
req := boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
resp := handler.RunFunc(req)
Expect(actionDispatcher.DispatchReq).To(Equal(req))
Expect(resp).To(Equal(expectedResp))
})
It("resumes persistent actions *before* dispatching new requests", func() {
resumedBeforeStartingToDispatch := false
handler.RunCallBack = func() {
resumedBeforeStartingToDispatch = actionDispatcher.ResumedPreviouslyDispatchedTasks
}
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(resumedBeforeStartingToDispatch).To(BeTrue())
})
Context("when heartbeats can be sent", func() {
BeforeEach(func() {
handler.KeepOnRunning()
})
BeforeEach(func() {
jobName := "fake-job"
nodeID := "node-id"
jobIndex := 1
specService.Spec = boshas.V1ApplySpec{
JobSpec: boshas.JobSpec{Name: &jobName},
Index: &jobIndex,
NodeID: nodeID,
}
jobSupervisor.StatusStatus = "fake-state"
platform.FakeVitalsService.GetVitals = boshvitals.Vitals{
Load: []string{"a", "b", "c"},
}
})
expectedJobName := "fake-job"
expectedJobIndex := 1
expectedNodeID := "node-id"
expectedHb := Heartbeat{
Job: &expectedJobName,
Index: &expectedJobIndex,
JobState: "fake-state",
NodeID: expectedNodeID,
Vitals: boshvitals.Vitals{Load: []string{"a", "b", "c"}},
}
//.........這裏部分代碼省略.........
示例8: init
func init() {
Describe("ApplyAction", func() {
var (
applier *fakeappl.FakeApplier
specService *fakeas.FakeV1Service
settingsService *fakesettings.FakeSettingsService
platform *fakeplatform.FakePlatform
dualDCSupport *nimbus.DualDCSupport
logger boshlog.Logger
action ApplyAction
)
BeforeEach(func() {
applier = fakeappl.NewFakeApplier()
specService = fakeas.NewFakeV1Service()
settingsService = &fakesettings.FakeSettingsService{}
platform = fakeplatform.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
dualDCSupport = nimbus.NewDualDCSupport(
platform.GetRunner(),
platform.GetFs(),
platform.GetDirProvider(),
specService,
settingsService,
logger,
)
action = NewApply(applier, specService, settingsService, dualDCSupport, platform)
})
It("apply should be asynchronous", func() {
Expect(action.IsAsynchronous()).To(BeTrue())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
Describe("Run", func() {
settings := boshsettings.Settings{AgentID: "fake-agent-id"}
BeforeEach(func() {
settingsService.Settings = settings
})
Context("when desired spec has configuration hash", func() {
currentApplySpec := boshas.V1ApplySpec{ConfigurationHash: "fake-current-config-hash"}
desiredApplySpec := boshas.V1ApplySpec{ConfigurationHash: "fake-desired-config-hash"}
populatedDesiredApplySpec := boshas.V1ApplySpec{
ConfigurationHash: "fake-populated-desired-config-hash",
}
Context("when current spec can be retrieved", func() {
BeforeEach(func() {
specService.Spec = currentApplySpec
})
It("populates dynamic networks in desired spec", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(specService.PopulateDHCPNetworksSpec).To(Equal(desiredApplySpec))
Expect(specService.PopulateDHCPNetworksSettings).To(Equal(settings))
})
Context("when resolving dynamic networks succeeds", func() {
BeforeEach(func() {
specService.PopulateDHCPNetworksResultSpec = populatedDesiredApplySpec
})
It("runs applier with populated desired spec", func() {
_, err := action.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(applier.Applied).To(BeTrue())
Expect(applier.ApplyCurrentApplySpec).To(Equal(currentApplySpec))
Expect(applier.ApplyDesiredApplySpec).To(Equal(populatedDesiredApplySpec))
})
Context("when applier succeeds applying desired spec", func() {
Context("when saving desires spec as current spec succeeds", func() {
It("returns 'applied' after setting populated desired spec as current spec", func() {
value, err := action.Run(desiredApplySpec)
Expect(err).ToNot(HaveOccurred())
Expect(value).To(Equal("applied"))
Expect(specService.Spec).To(Equal(populatedDesiredApplySpec))
})
})
Context("when saving populated desires spec as current spec fails", func() {
It("returns error because agent was not able to remember that is converged to desired spec", func() {
specService.SetErr = errors.New("fake-set-error")
_, err := action.Run(desiredApplySpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-set-error"))
})
})
})
Context("when applier fails applying desired spec", func() {
//.........這裏部分代碼省略.........
示例9: describeConfigDriveMetadataService
func describeConfigDriveMetadataService() {
var (
metadataService MetadataService
resolver *fakeinf.FakeDNSResolver
platform *fakeplatform.FakePlatform
logger boshlog.Logger
)
updateMetadata := func(metadataContents MetadataContentsType) {
metadataJSON, err := json.Marshal(metadataContents)
Expect(err).ToNot(HaveOccurred())
platform.SetGetFilesContentsFromDisk("/fake-disk-path-1/fake-metadata-path", metadataJSON, nil)
Expect(metadataService.IsAvailable()).To(BeTrue())
}
updateUserdata := func(userdataContents string) {
platform.SetGetFilesContentsFromDisk("/fake-disk-path-1/fake-userdata-path", []byte(userdataContents), nil)
Expect(metadataService.IsAvailable()).To(BeTrue())
}
BeforeEach(func() {
resolver = &fakeinf.FakeDNSResolver{}
platform = fakeplatform.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
diskPaths := []string{
"/fake-disk-path-1",
"/fake-disk-path-2",
}
metadataService = NewConfigDriveMetadataService(
resolver,
platform,
diskPaths,
"fake-metadata-path",
"fake-userdata-path",
logger,
)
userdataContents := fmt.Sprintf(`{"server":{"name":"fake-server-name"},"registry":{"endpoint":"fake-registry-endpoint"}}`)
platform.SetGetFilesContentsFromDisk("/fake-disk-path-1/fake-userdata-path", []byte(userdataContents), nil)
metadata := MetadataContentsType{
PublicKeys: map[string]PublicKeyType{
"0": PublicKeyType{
"openssh-key": "fake-openssh-key",
},
},
InstanceID: "fake-instance-id",
}
updateMetadata(metadata)
})
Describe("GetNetworks", func() {
It("returns the network settings", func() {
userdataContents := `
{
"networks": {
"network_1": {"type": "manual", "ip": "1.2.3.4", "netmask": "2.3.4.5", "gateway": "3.4.5.6", "default": ["dns"], "dns": ["8.8.8.8"], "mac": "fake-mac-address-1"},
"network_2": {"type": "dynamic", "default": ["dns"], "dns": ["8.8.8.8"], "mac": "fake-mac-address-2"}
}
}`
updateUserdata(userdataContents)
networks, err := metadataService.GetNetworks()
Expect(err).ToNot(HaveOccurred())
Expect(networks).To(Equal(boshsettings.Networks{
"network_1": boshsettings.Network{
Type: "manual",
IP: "1.2.3.4",
Netmask: "2.3.4.5",
Gateway: "3.4.5.6",
Default: []string{"dns"},
DNS: []string{"8.8.8.8"},
Mac: "fake-mac-address-1",
},
"network_2": boshsettings.Network{
Type: "dynamic",
Default: []string{"dns"},
DNS: []string{"8.8.8.8"},
Mac: "fake-mac-address-2",
},
}))
})
It("returns a nil Networks if the settings are missing (from an old CPI version)", func() {
userdataContents := `{}`
updateUserdata(userdataContents)
networks, err := metadataService.GetNetworks()
Expect(err).ToNot(HaveOccurred())
Expect(networks).To(BeNil())
})
})
Describe("IsAvailable", func() {
It("return true when it can load successfully", func() {
Expect(metadataService.IsAvailable()).To(BeTrue())
})
//.........這裏部分代碼省略.........
示例10: init
func init() {
Describe("Start", func() {
var (
jobSupervisor *fakejobsuper.FakeJobSupervisor
applier *fakeappl.FakeApplier
specService *fakeas.FakeV1Service
platform *fakeplatform.FakePlatform
settingsService *fakesettings.FakeSettingsService
logger boshlog.Logger
dualDCSupport *nimbus.DualDCSupport
action StartAction
)
BeforeEach(func() {
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
applier = fakeappl.NewFakeApplier()
specService = fakeas.NewFakeV1Service()
action = NewStart(jobSupervisor, applier, specService, dualDCSupport, platform)
platform = fakeplatform.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
settingsService = &fakesettings.FakeSettingsService{}
dualDCSupport = nimbus.NewDualDCSupport(
platform.GetRunner(),
platform.GetFs(),
platform.GetDirProvider(),
specService,
settingsService,
logger,
)
action = NewStart(jobSupervisor, applier, specService, dualDCSupport, platform)
})
It("is synchronous", func() {
Expect(action.IsAsynchronous()).To(BeFalse())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("returns started", func() {
started, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(started).To(Equal("started"))
})
It("starts monitor services", func() {
_, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(jobSupervisor.Started).To(BeTrue())
})
It("configures jobs", func() {
_, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(applier.Configured).To(BeTrue())
})
It("apply errs if a job fails configuring", func() {
applier.ConfiguredError = errors.New("fake error")
_, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Configuring jobs"))
})
})
}
示例11: buildSSHAction
func buildSSHAction(settingsService boshsettings.Service) (*fakeplatform.FakePlatform, SSHAction) {
platform := fakeplatform.NewFakePlatform()
dirProvider := boshdirs.NewDirectoriesProvider("/foo")
action := NewSSH(settingsService, platform, dirProvider)
return platform, action
}
示例12: 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)
//.........這裏部分代碼省略.........
示例13: init
func init() {
Describe("natsHandler", func() {
var (
settingsService *fakesettings.FakeSettingsService
client *fakeyagnats.FakeYagnats
logger boshlog.Logger
handler boshhandler.Handler
platform *fakeplatform.FakePlatform
loggerOutBuf *bytes.Buffer
loggerErrBuf *bytes.Buffer
)
BeforeEach(func() {
settingsService = &fakesettings.FakeSettingsService{
Settings: boshsettings.Settings{
AgentID: "my-agent-id",
Mbus: "nats://fake-username:[email protected]:1234",
},
}
loggerOutBuf = bytes.NewBufferString("")
loggerErrBuf = bytes.NewBufferString("")
logger = boshlog.NewWriterLogger(boshlog.LevelError, loggerOutBuf, loggerErrBuf)
client = fakeyagnats.New()
platform = fakeplatform.NewFakePlatform()
handler = NewNatsHandler(settingsService, client, logger, platform)
})
Describe("Start", func() {
It("starts", func() {
var receivedRequest boshhandler.Request
handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
receivedRequest = req
return boshhandler.NewValueResponse("expected value")
})
defer handler.Stop()
Expect(client.ConnectedConnectionProvider()).ToNot(BeNil())
Expect(client.SubscriptionCount()).To(Equal(1))
subscriptions := client.Subscriptions("agent.my-agent-id")
Expect(len(subscriptions)).To(Equal(1))
expectedPayload := []byte(`{"method":"ping","arguments":["foo","bar"], "reply_to": "reply to me!"}`)
subscription := subscriptions[0]
subscription.Callback(&yagnats.Message{
Subject: "agent.my-agent-id",
Payload: expectedPayload,
})
Expect(receivedRequest).To(Equal(boshhandler.Request{
ReplyTo: "reply to me!",
Method: "ping",
Payload: expectedPayload,
}))
Expect(client.PublishedMessageCount()).To(Equal(1))
messages := client.PublishedMessages("reply to me!")
Expect(len(messages)).To(Equal(1))
Expect(messages[0].Payload).To(Equal([]byte(`{"value":"expected value"}`)))
})
It("cleans up ip-mac address cache for nats configured with ip address", func() {
handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
return nil
})
defer handler.Stop()
Expect(platform.CleanedIPMacAddressCache).To(Equal("127.0.0.1"))
Expect(client.ConnectedConnectionProvider()).ToNot(BeNil())
})
It("does not try to clean up ip-mac address cache for nats configured with hostname", func() {
settingsService.Settings.Mbus = "nats://fake-username:[email protected]:1234"
handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
return nil
})
defer handler.Stop()
Expect(platform.CleanedIPMacAddressCache).To(BeEmpty())
Expect(client.ConnectedConnectionProvider()).ToNot(BeNil())
})
It("logs error and proceeds if it fails to clean up ip-mac address cache for nats", func() {
platform.CleanIPMacAddressCacheErr = errors.New("failed to run")
handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
return nil
})
defer handler.Stop()
Expect(platform.CleanedIPMacAddressCache).To(Equal("127.0.0.1"))
Expect(loggerErrBuf).To(ContainSubstring("ERROR - Cleaning ip-mac address cache for: 127.0.0.1"))
Expect(client.ConnectedConnectionProvider()).ToNot(BeNil())
})
It("does not respond if the response is nil", func() {
err := handler.Start(func(req boshhandler.Request) (resp boshhandler.Response) {
return nil
//.........這裏部分代碼省略.........
示例14:
blobstore *fakeblobstore.FakeBlobstore
taskService *faketask.FakeService
notifier *fakenotif.FakeNotifier
applier *fakeappl.FakeApplier
compiler *fakecomp.FakeCompiler
jobSupervisor *fakejobsuper.FakeJobSupervisor
specService *fakeas.FakeV1Service
drainScriptProvider boshdrain.ScriptProvider
jobScriptProvider boshscript.JobScriptProvider
factory Factory
logger boshlog.Logger
)
BeforeEach(func() {
settingsService = &fakesettings.FakeSettingsService{}
platform = fakeplatform.NewFakePlatform()
blobstore = &fakeblobstore.FakeBlobstore{}
taskService = &faketask.FakeService{}
notifier = fakenotif.NewFakeNotifier()
applier = fakeappl.NewFakeApplier()
compiler = fakecomp.NewFakeCompiler()
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
drainScriptProvider = boshdrain.NewConcreteScriptProvider(nil, nil, platform.GetDirProvider())
jobScriptProvider = &fakescript.FakeJobScriptProvider{}
logger = boshlog.NewLogger(boshlog.LevelNone)
factory = NewFactory(
settingsService,
platform,
blobstore,
示例15: 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"))
//.........這裏部分代碼省略.........