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


Golang fakes.FakeSettingsService類代碼示例

本文整理匯總了Golang中bosh/settings/fakes.FakeSettingsService的典型用法代碼示例。如果您正苦於以下問題:Golang FakeSettingsService類的具體用法?Golang FakeSettingsService怎麽用?Golang FakeSettingsService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: init

func init() {
	Describe("concreteBuilder", func() {
		var (
			settingsService *fakesettings.FakeSettingsService
			builder         Builder
		)

		BeforeEach(func() {
			logger := boshlog.NewLogger(boshlog.LEVEL_NONE)
			settingsService = &fakesettings.FakeSettingsService{}
			builder = NewBuilder(settingsService, logger)
		})

		Describe("Build", func() {
			It("builds alert with id, severity and other monit related info", func() {
				builtAlert, err := builder.Build(buildMonitAlert())
				Expect(err).ToNot(HaveOccurred())

				expectedAlert := Alert{
					Id:        "some random id",
					Severity:  SEVERITY_ALERT,
					Title:     "nats - does not exist - restart",
					Summary:   "process is not running",
					CreatedAt: 1306076861,
				}

				Expect(builtAlert).To(Equal(expectedAlert))
			})

			It("sets the severity based on event", func() {
				alerts := map[string]SeverityLevel{
					"action done": SEVERITY_IGNORED,
					"Action done": SEVERITY_IGNORED,
					"action Done": SEVERITY_IGNORED,
				}

				for event, expectedSeverity := range alerts {
					inputAlert := buildMonitAlert()
					inputAlert.Event = event
					builtAlert, _ := builder.Build(inputAlert)
					Expect(builtAlert.Severity).To(Equal(expectedSeverity))
				}
			})

			It("sets default severity to critical", func() {
				inputAlert := buildMonitAlert()
				inputAlert.Event = "some unknown event"

				builtAlert, _ := builder.Build(inputAlert)
				Expect(builtAlert.Severity).To(Equal(SEVERITY_CRITICAL))
			})

			It("sets created at", func() {
				inputAlert := buildMonitAlert()
				inputAlert.Date = "Thu, 02 May 2013 20:07:41 +0500"

				builtAlert, _ := builder.Build(inputAlert)
				Expect(int(builtAlert.CreatedAt)).To(Equal(int(1367507261)))
			})

			It("defaults created at to now on parse error", func() {
				inputAlert := buildMonitAlert()
				inputAlert.Date = "Thu, 02 May 2013 20:07:0"

				builtAlert, _ := builder.Build(inputAlert)

				createdAt := time.Unix(builtAlert.CreatedAt, 0)
				now := time.Now()

				assert.WithinDuration(GinkgoT(), now, createdAt, 1*time.Second)
			})

			It("sets the title with ips", func() {
				inputAlert := buildMonitAlert()
				settingsService.Ips = []string{"192.168.0.1", "10.0.0.1"}

				builtAlert, _ := builder.Build(inputAlert)

				Expect(builtAlert.Title).To(Equal("nats (10.0.0.1, 192.168.0.1) - does not exist - restart"))
			})
		})
	})
}
開發者ID:velankanisys,項目名稱:bosh,代碼行數:83,代碼來源:concrete_builder_test.go

示例2: init

func init() {
	Describe("prepareNetworkChange", func() {
		var (
			action          PrepareNetworkChangeAction
			fs              *fakesys.FakeFileSystem
			settingsService *fakesettings.FakeSettingsService
		)

		BeforeEach(func() {
			fs = fakesys.NewFakeFileSystem()
			settingsService = &fakesettings.FakeSettingsService{}
			action = NewPrepareNetworkChange(fs, settingsService)
		})

		It("is synchronous", func() {
			Expect(action.IsAsynchronous()).To(BeFalse())
		})

		It("is not persistent", func() {
			Expect(action.IsPersistent()).To(BeFalse())
		})

		It("invalidates settings so that load settings cannot fall back on old settings", func() {
			resp, err := action.Run()
			Expect(err).NotTo(HaveOccurred())
			Expect(resp).To(Equal("ok"))

			Expect(settingsService.SettingsWereInvalidated).To(BeTrue())
		})

		Context("when settings invalidation succeeds", func() {
			Context("when the network rules file can be removed", func() {
				It("removes the network rules file", func() {
					fs.WriteFile("/etc/udev/rules.d/70-persistent-net.rules", []byte{})

					resp, err := action.Run()
					Expect(err).NotTo(HaveOccurred())
					Expect(resp).To(Equal("ok"))

					Expect(fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules")).To(BeFalse())
				})
			})

			Context("when the network rules file cannot be removed", func() {
				BeforeEach(func() {
					fs.RemoveAllError = errors.New("fake-remove-all-error")
				})

				It("returns error from removing the network rules file", func() {
					resp, err := action.Run()
					Expect(err).To(HaveOccurred())
					Expect(err.Error()).To(ContainSubstring("fake-remove-all-error"))

					Expect(resp).To(BeNil())
				})
			})
		})

		Context("when settings invalidation fails", func() {
			BeforeEach(func() {
				settingsService.InvalidateSettingsError = errors.New("fake-invalidate-error")
			})

			It("returns error early if settings err invalidating", func() {
				resp, err := action.Run()
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(ContainSubstring("fake-invalidate-error"))

				Expect(resp).To(BeNil())
			})

			It("does not remove the network rules file", func() {
				fs.WriteFile("/etc/udev/rules.d/70-persistent-net.rules", []byte{})

				action.Run()
				Expect(fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules")).To(BeTrue())
			})
		})
	})
}
開發者ID:Bosh-for-Cpi,項目名稱:bosh-2605,代碼行數:80,代碼來源:prepare_network_change_test.go

示例3: init

func init() {
	Describe("bootstrap", func() {
		Describe("Run", func() {
			var (
				inf         *fakeinf.FakeInfrastructure
				platform    *fakeplatform.FakePlatform
				dirProvider boshdir.DirectoriesProvider

				settingsServiceProvider *fakesettings.FakeSettingsServiceProvider
				settingsService         *fakesettings.FakeSettingsService
			)

			BeforeEach(func() {
				inf = &fakeinf.FakeInfrastructure{
					GetEphemeralDiskPathFound:    true,
					GetEphemeralDiskPathRealPath: "/dev/sdz",
				}
				platform = fakeplatform.NewFakePlatform()
				dirProvider = boshdir.NewDirectoriesProvider("/var/vcap")

				settingsServiceProvider = fakesettings.NewServiceProvider()
				settingsService = settingsServiceProvider.NewServiceSettingsService
			})

			bootstrap := func() (boshsettings.Service, error) {
				logger := boshlog.NewLogger(boshlog.LevelNone)
				return New(inf, platform, dirProvider, settingsServiceProvider, logger).Run()
			}

			It("sets up runtime configuration", func() {
				_, err := bootstrap()
				Expect(err).NotTo(HaveOccurred())
				Expect(platform.SetupRuntimeConfigurationWasInvoked).To(BeTrue())
			})

			It("sets up ssh", func() {
				_, err := bootstrap()
				Expect(err).NotTo(HaveOccurred())
				Expect(inf.SetupSshUsername).To(Equal("vcap"))
			})

			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("returns the settings service", func() {
				settingsService, err := bootstrap()
				Expect(err).NotTo(HaveOccurred())
				Expect(settingsService).To(Equal(settingsService))

				Expect(settingsServiceProvider.NewServiceFs).To(Equal(platform.GetFs()))
				Expect(settingsServiceProvider.NewServiceDir).To(Equal(dirProvider.BoshDir()))

				fetchedSettings, err := settingsServiceProvider.NewServiceFetcher()
				Expect(err).NotTo(HaveOccurred())
				Expect(fetchedSettings).To(Equal(inf.Settings))
			})

			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() {
				networks := boshsettings.Networks{
					"bosh": boshsettings.Network{},
				}
				settingsService.Settings.Networks = networks

				_, err := bootstrap()
				Expect(err).NotTo(HaveOccurred())
				Expect(inf.SetupNetworkingNetworks).To(Equal(networks))
			})

			It("sets up ephemeral disk", func() {
				settingsService.Disks = boshsettings.Disks{
					Ephemeral: "fake-ephemeral-disk-setting",
				}

				inf.GetEphemeralDiskPathRealPath = "/dev/sda"
				inf.GetEphemeralDiskPathFound = true

				_, err := bootstrap()
				Expect(err).NotTo(HaveOccurred())
				Expect(platform.SetupEphemeralDiskWithPathDevicePath).To(Equal("/dev/sda"))
				Expect(inf.GetEphemeralDiskPathDevicePath).To(Equal("fake-ephemeral-disk-setting"))
			})
//.........這裏部分代碼省略.........
開發者ID:Jane4PKU,項目名稱:bosh,代碼行數:101,代碼來源:bootstrap_test.go

示例4:

import (
	"errors"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	. "bosh/agent/action"
	fakeplatform "bosh/platform/fakes"
	boshdirs "bosh/settings/directories"
	fakesettings "bosh/settings/fakes"
)

var _ = Describe("MountDiskAction", func() {
	var (
		settingsService *fakesettings.FakeSettingsService
		platform        *fakeplatform.FakePlatform
		action          MountDiskAction
	)

	BeforeEach(func() {
		settingsService = &fakesettings.FakeSettingsService{}
		platform = fakeplatform.NewFakePlatform()
		dirProvider := boshdirs.NewDirectoriesProvider("/fake-base-dir")
		action = NewMountDisk(settingsService, platform, platform, dirProvider)
	})

	It("is asynchronous", func() {
		Expect(action.IsAsynchronous()).To(BeTrue())
	})

	It("is not persistent", func() {
開發者ID:Bosh-for-Cpi,項目名稱:bosh-2605,代碼行數:31,代碼來源:mount_disk_test.go

示例5: init

func init() {
	Describe("ApplyAction", func() {
		var (
			applier         *fakeappl.FakeApplier
			specService     *fakeas.FakeV1Service
			settingsService *fakesettings.FakeSettingsService
			action          ApplyAction
		)

		BeforeEach(func() {
			applier = fakeappl.NewFakeApplier()
			specService = fakeas.NewFakeV1Service()
			settingsService = &fakesettings.FakeSettingsService{}
			action = NewApply(applier, specService, settingsService)
		})

		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.PopulateDynamicNetworksSpec).To(Equal(desiredApplySpec))
						Expect(specService.PopulateDynamicNetworksSettings).To(Equal(settings))
					})

					Context("when resolving dynamic networks succeeds", func() {
						BeforeEach(func() {
							specService.PopulateDynamicNetworksResultSpec = 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() {
							BeforeEach(func() {
								applier.ApplyError = errors.New("fake-apply-error")
							})

							It("returns error", func() {
								_, err := action.Run(desiredApplySpec)
								Expect(err).To(HaveOccurred())
								Expect(err.Error()).To(ContainSubstring("fake-apply-error"))
							})

							It("does not save desired spec as current spec", func() {
								_, err := action.Run(desiredApplySpec)
								Expect(err).To(HaveOccurred())
								Expect(specService.Spec).To(Equal(currentApplySpec))
//.........這裏部分代碼省略.........
開發者ID:Bosh-for-Cpi,項目名稱:bosh-2605,代碼行數:101,代碼來源:apply_test.go

示例6:

	fakeas "bosh/agent/applier/applyspec/fakes"
	boshassert "bosh/assert"
	fakejobsuper "bosh/jobsupervisor/fakes"
	boshntp "bosh/platform/ntp"
	fakentp "bosh/platform/ntp/fakes"
	boshvitals "bosh/platform/vitals"
	fakevitals "bosh/platform/vitals/fakes"
	boshsettings "bosh/settings"
	fakesettings "bosh/settings/fakes"
)

var _ = Describe("GetState", func() {
	var (
		settings      *fakesettings.FakeSettingsService
		specService   *fakeas.FakeV1Service
		jobSupervisor *fakejobsuper.FakeJobSupervisor
		vitalsService *fakevitals.FakeService
		action        GetStateAction
	)

	BeforeEach(func() {
		settings = &fakesettings.FakeSettingsService{}
		jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
		specService = fakeas.NewFakeV1Service()
		vitalsService = fakevitals.NewFakeService()
		action = NewGetState(settings, specService, jobSupervisor, vitalsService, &fakentp.FakeService{
			GetOffsetNTPOffset: boshntp.NTPInfo{
				Offset:    "0.34958",
				Timestamp: "12 Oct 17:37:58",
			},
		})
開發者ID:Jane4PKU,項目名稱:bosh,代碼行數:31,代碼來源:get_state_test.go

示例7:

import (
	"errors"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	. "bosh/agent/action"
	fakeplatform "bosh/platform/fakes"
	fakesettings "bosh/settings/fakes"
)

var _ = Describe("prepareConfigureNetworks", func() {
	var (
		action          PrepareConfigureNetworksAction
		platform        *fakeplatform.FakePlatform
		settingsService *fakesettings.FakeSettingsService
	)

	BeforeEach(func() {
		platform = fakeplatform.NewFakePlatform()
		settingsService = &fakesettings.FakeSettingsService{}
		action = NewPrepareConfigureNetworks(platform, settingsService)
	})

	It("is synchronous", func() {
		Expect(action.IsAsynchronous()).To(BeFalse())
	})

	It("is not persistent", func() {
		Expect(action.IsPersistent()).To(BeFalse())
開發者ID:Bosh-for-Cpi,項目名稱:bosh-2605,代碼行數:30,代碼來源:prepare_configure_networks_test.go


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